1.

What is a Nested Top-level class in Java

Answer»

Nested classes in Java is declared inside a CLASS or interface. Non-STATIC nested classes are known as inner class in Java as there are two types of nested classes i.e. static and non-static.

A PROGRAM that demonstrates an inner class in Java is given as follows:

class Outer {   class Inner   {      public void display()      {           System.out.println("Inside the inner class method");      }   } } public class MAIN {   public static void main(String[] args)   {       Outer.Inner obj = NEW Outer().new Inner();       obj.display();   } }

The output of the above program is as follows:

Inside the inner class method


Discussion

No Comment Found