Posts

Showing posts with the label Nested class and inner class in Java

nested class and inner class in Java

  Nested classes : It is possible to define a class within another class; such classes are known as nested classes. There are two types of nested classes : A. static nested class B. non-static (inner) class A. Static nested class : A static class created within class. These are the static members of a class. Syntax : class Outer {     static class inner     { //code       } } Example : class outer {     static class inner    {      void show()     {       System.out.println("static nested  class ");      }   } } public class Test { public static void main(String args[]) { outer.inner i =new outer.inner(); i.show(); } } Output : static nested class  B. Non-static nested class (inner class) : Inner class is a non-static nested class. It has access to all of the variables and ...