0

I am trying to understand how member classes works in java , but when i try this code

public class Class1 {
    public static void main(String[] args) {
        Class2 c = new Class2();
        c.show();
    }

    class Class2 {
        public void show() {
            System.out.println("helloworld");
        }
    }

}

i receive this error No enclosing instance of type Class1 is accessible. Must qualify the allocation with an enclosing instance of type Class1 (e.g. x.new A() where x is an instance of Class1) and i cant understand why!

Andi Domi
  • 731
  • 2
  • 19
  • 48

0 Answers0