http://renyanwei.iteye.com/blog/258304
First look at the rules for overriding and hiding methods and variables in Java when they inherit
1. Instance and static variables of the parent class can be hidden by a variable of the same name in the quilt class
2. Static method of the parent class the quilt class with the same name static method hidden
3. Instance methods of the parent class overridden by an instance variable of the same name in the quilt class
There are a few more things to note.
1. You cannot use a static method of a subclass to hide An instance method that is equally marked in the parent class (that is, the return value name parameter is the same)
2. You cannot overwrite a static method that is equally marked in a parent class with an instance method of a subclass
3. Craved note that the variable will only be hidden and will not be overwritten , whether he is an instance variable or a static variable, and that a static variable of the subclass can hide The instance variable of the parent class, and the instance variable of the subclass can be hidden Static variables of the parent class
Let's summarize.
1. Instance methods with the same name are overwritten , static methods with the same name are hidden , and the GetName instance method of the child class overrides the GetName instance method of the parent, Chind Getkind method Hides the Getkind method of the parent class
2. the difference between hiding and overriding is that when a subclass object is converted to a parent class object, it is able to access the hidden variables and methods of the parent class, and cannot access the method that the parent class is overridden
3. If you need to access an instance variable that the parent class is hidden , plus super, such as accessing the name of the parent class, write Super.name.
overriding and hiding methods and variables in Java in inheritance