1

Noob here. I have tried the following code, but it appears that Java cannot find InnerClass2 when nested. I could not find any guide on how to fix this issue. I also tried InnerClass2 in = Main.new InnerClass2(); but it did not work either. Thoughts?

public class Main {
  public static void main(String[] args) {
   InnerClass2 in = new InnerClass2();
   class InnerClass2 {
     InnerClass2(){
     }
    }
   }
  }
uweo030
  • 33
  • 4

1 Answers1

0

You can't declare a class within a method. You could instead declare it inside the Main class:

public class Main {
  public static class InnerClass2 {
    // class details
  }
  public static void main(String[] args) {
    InnerClass2 in = new InnerClass2();
  }
}
Mureinik
  • 297,002
  • 52
  • 306
  • 350