java - IN主类不能调用子类
问题描述
import org.w3c.dom.ls.LSOutput;
public class Super {
int x = 155;
void display1() {
System.out.println("values is " + x);
}
class Sub extends Super {
int y = 587;
void display2() {
System.out.println("values was " + x);
System.out.println("valus is. " + y);
}
}
}
***********主课**************
public class Main {
public static void main(String[] args) {
Super ss = new Super();
ss.display1();
//how to call sub class. it is giving error : super is not an enclosed class
Super.Sub rr = new Super.Sub();
rr.display2();
}
}
解决方案
代替
Super.Sub rr = new Super.Sub();
和
Super.Sub rr = new Super().new Sub();
或声明Sub
为static class
.
检查此以了解更多信息。
推荐阅读
- python - Mac OSError: [Errno -9996](无默认输出设备)
- python-3.x - 循环列并计算组内的相对变化
- python - datetime.strptime - 不接受在 Linux(Ubuntu) 上运行的缩写德语月份。有解决方法吗?
- asp.net-mvc - F# ASP.net MVC 项目不会在 VS 2019 中编译
- python - 如何删除字节列表中的特定元素,如对象
- go - 无法使用 Go 的“文本/模板”库导入变量
- outlook - 需要帮助以修复响应式电子邮件中的 webkit 错误
- django - 当前用户以外的其他用户的 PassWordChangeForm
- java - 我可以在自动化测试期间从 HttpRequest 捕获 JSON 有效负载(JUnit 或带有 Selenium 的 TestNG)吗?
- vba - 我可以在 vba 中使用哪个函数,类似于我在 sql 中使用的函数