静态方法和静态属性属于类本身,无法被子类重写
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); } }
原文:https://www.cnblogs.com/When6/p/12310695.html