Analysis of essential examples of method rewriting in java
Today Xiaobian to share with you the java method rewriting of the essence of the case analysis related knowledge points, detailed content, logic clear, I believe most people are still too familiar with this knowledge, so share this article for your reference, I hope you read this article after some harvest, let's learn about it together.
essential description
In the compilation phase, the compiler only knows the static type of the object, but does not know the actual type, so it can only determine the method of calling the parent class in the class file.
During execution, it will determine the actual type of object. If the actual type implements this method, it will be called directly. If it is not implemented, it will be retrieved from the bottom up according to the inheritance relationship. As soon as it is retrieved, it will be invoked. If it is not retrieved, it will be discarded.
examples
class Animal { void eat() { System.out.println("eating... "); }} class Dog extends Animal { void eat() { System.out.println("eating bread... "); }} The above is all the content of this article "Analysis of the essence of method rewriting in java", thank you for reading! I believe everyone has a great harvest after reading this article. Xiaobian will update different knowledge for everyone every day. If you want to learn more knowledge, please pay attention to the industry information channel.