静态类不能被继承(其继承类不能被实例化,等于不能继承)-创新互联

开始听同事在那讨论,有人问静态类是否能被继承,我觉得是不能,但没有找到有说服力的例子,于是写了一段简单的代码来测试,如下:
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://www.hxwzsj.com/article/idsoi.html

其他资讯

Copyright © 2025 青羊区翔捷宏鑫字牌设计制作工作室(个体工商户) All Rights Reserved 蜀ICP备2025123194号-14
友情链接: 定制级高端网站建设 成都网站建设 成都网站建设公司 四川成都网站设计 外贸网站建设 高端网站设计 上市集团网站建设 温江网站设计 网站建设 网站制作公司 网站制作 成都网站制作 企业网站设计 成都网站设计 成都网站制作 企业手机网站建设 成都企业网站设计 响应式网站建设 网站设计 企业网站制作 公司网站建设 H5网站制作