静态方法和静态属性----不能实现多态

静态方法和静态属性属于类本身,无法被子类重写

class A{
    private int i = 1;    
    private void f(){
        
    }
    public static int j=3;
    public static void o()
    {
        System.out.println("aaaaaaaaaaa");
    }
    
}
public class B extends A {
    public static int j=9;
    public static void o()
    {
        System.out.println("bbbbb");
    }

}
import java.util.*;

public class Test{
    public static void main(String[] args){
    A a =new B();
    a.o();
    System.out.println(a.j);
    B b =(B)a;
    b.o();
    System.out.println(b.j);
    }
}

 

posted @ 2020-02-15 09:35  When?  阅读(313)  评论(0编辑  收藏  举报