Explanation
1. Member variables, look at the left side when compiling, and look at the left side when running.
2.Construction methods, subclass constructions will access the parent class construction by default
3. Member methods, look on the left when compiling, and look on the right when running.
4. Static methods, look on the left when compiling, and look on the left when running.
Example
package day09; /* * 成员变量: * 编译看左边(父类),运行看左边(父类) * */ class Demo_PolyMorphic { public static void main(String[]args){ Father f=new Son(); System.out.println(f.num); Son s=new Son(); System.out.println(s.num); } } class Father{ int num=10; } class Son extends Father{ int num=20; }
The above is the detailed content of How to access members in polymorphism in java. For more information, please follow other related articles on the PHP Chinese website!