Java 在主类中可以';I don’我不叫小班
***********主类**************Java 在主类中可以';I don’我不叫小班,java,Java,***********主类************** 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()
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();
}
}
与
或者将Sub
声明为静态类
检查以了解更多信息。欢迎使用堆栈溢出。如果您只是将任意代码转储到问题的主体中,而根本没有描述问题,那么您就不可能期望得到一个连贯的答案。
Super.Sub rr = new Super.Sub();
Super.Sub rr = new Super().new Sub();