类绑定----多态执行问题【编译看左,运行看右】

成员变量,静态方法看左边;非静态方法:编译看左边,运行看右边。

 1 public class BoundDemo {
 2     public static void main(String[] args) {
 3         A a=new B();
 4         System.err.println(a.age);
 5         System.err.println(a.num);
 6         a.abc();
 7         a.abcd();
 8     }
 9     
10 }
11 
12 class A
13 {
14     public int age=100;
15     public static int num=100;
16     public static void abc()
17     {
18         System.err.println("100......");
19     }
20     public void abcd()
21     {
22         System.err.println("100.......");
23     }
24 }
25 
26 class B extends A
27 {
28     public int age=1000;
29     public static int num=1000;
30     public static void abc()
31     {
32         System.err.println("1000......");
33     }
34     public void abcd()
35     {
36         System.err.println("1000.......");
37     }
38 }

原文地址:https://www.cnblogs.com/liuwt365/p/4169443.html