Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在主类中可以';I don’我不叫小班_Java - Fatal编程技术网

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();