0
class Outer {

    class Inner {
        void print() {
            System.out.println("Inner printing");
        }
    }


    public static void main(String[] args) {
        (new Outer().new Inner()).print();
    }
}

What is the syntax of (new Outer().new Inner())? Why the new operator is used after a object?

Name Null
  • 390
  • 2
  • 11
  • [The java tutorials - Nested Classes](https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html) - What you have here is an inner class as the same would suggest. – OH GOD SPIDERS Nov 17 '22 at 10:35
  • The class Inner is defined inside the class Outer, so the dot qualifies its name as Outer.Inner. The fact that the class Inner is not static, requires an instance of Outer to be created before you can create an instance of Inner. – Matteo NNZ Nov 17 '22 at 10:38

0 Answers0