Chinaunix

标题: 关于java继承的一点问题.. [打印本页]

作者: uumylife    时间: 2007-11-04 00:04
标题: 关于java继承的一点问题..
关于java继承的一点问题..

class SuperShow{
public static String str="superStr";
public void show(){
System.out.println("SuperShow:"+str);
}
}
public class ExtendShow extends SuperShow{
public static String str="ExtendStr";
public void show(){
System.out.println("ExtendShow:"+str);
}
public static void main(String args[]){
ExtendShow extend=new ExtendShow();
SuperShow supe=extend;
extend.show();
supe.show();
System.out.println("\n");
System.out.println("extend.str="+extend.str);
System.out.println("supe.str="+supe.str);
}
}
这段代码,输出结果:
ExtendShow:ExtendStr
ExtendShow:ExtendStr
extend.str=ExtendStr
supe.str=superStr


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/49841/showart_414073.html




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2