static、final修饰的变量和方法能否被继承的问题
首先定义父类和子类
public class Parent {
protected static String a = "static";
final String b = "final";
public static void staticMethod(){
System.out.println("this is a static method");
}
public final void finalMethod(){
System.out.println("this is a final method");
}
}
public class Child extends Parent {
@Test
public void test(){
System.out.println(a);
System.out.println(b);
staticMethod();
finalMethod(http://www.my516.com);
}
}
输出的结果是这样的:
static
final
this is a static method
this is a final method
由此可见,只要是非私有的成员都是可以被继承的,并且也可以在子类对其进行覆盖!
---------------------