标题: 子类和父类的static成员 [打印本页] 作者: fso918 时间: 2011-10-18 15:03 标题: 子类和父类的static成员 父类:
class Super{
public static void say(){
System.out.println("Hello,Tom");
}
}
子类:
class Sub extends Super{
public static void say(){
System.out.println("Hi,Jacl");
}
}
测试类:
class Test{
public static void main(String[] args){
Super s = new Sub();
s.say();
}
}
父类:
package com.super;
public class Super{
static String s = "Tom";
public static void say(){
System.out.println("Hello," + s);
}
}
子类:
package com.subclass;
public class Sub extends Super{
public static void say(){
System.out.println("Hi," + s);
}
}
测试类:
class Test{
public static void main(String[] args){
Super s = new Sub();
s.say();
}
}