java中多态时编译以及运行成员变量及函数分析

来源:互联网 发布:ads射频仿真软件 编辑:程序博客网 时间:2024/06/05 09:00
public class A {
public static void main(String[] args) {
B b = new C();
b.method();
}
}


class B {
final int a;

{
a = 10;
}

B() {
}
public static void method() {
System.out.println("B");
}
}


class C extends B {
C() {
}


public static void method() {
System.out.println("C");
}

}

输出:B

成员访问特点
成员变量:编译看左边,运行看左边
成员方法:编译看左边,运行看右边
静态方法:编译看左边,运行看左边
=>所以说静态方法不能算方法的重写


0 0
原创粉丝点击