RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
静态类不能被继承(其继承类不能被实例化,等于不能继承)

开始听同事在那讨论,有人问静态类是否能被继承,我觉得是不能,但没有找到有说服力的例子,于是写了一段简单的代码来测试,如下:
public class staticTest {
static class aa{
void abc(){
System.out.println("1111111");
}
}

class bb extends aa{
void abc(){
System.out.println("222222");
}
}

在良庆等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供做网站、成都网站制作 网站设计制作按需定制,公司网站建设,企业网站建设,成都品牌网站建设,成都营销网站建设,外贸营销网站建设,良庆网站建设费用合理。

public static void main(String[] args) {
//bb x = new bb();
aa y = new aa();
y.abc();
}
}
其中aa为静态类,bb为其继承类,类aa能像aa y = new aa();实例化,但类bb却会出错,eclipse中提示为No enclosing instance of type staticTest is accessible. Must qualify the allocation with an enclosing instance of type staticTest (e.g. x.new A() where x is an instance of staticTest).
经过多次试验,均不知道如何实例化类bb,故我的结论是类bb不能实例化。因为静态类aa的继承类bb无法实例化,类bb名存实亡,故认为静态类aa不能被继承。
(若谁知道如何实例化以上代码中的类bb,请回复代码,感谢!)

[@more@]
文章名称:静态类不能被继承(其继承类不能被实例化,等于不能继承)
当前路径:http://sczitong.cn/article/ihghge.html