Posts

Inner Classes in Java

Image
 Inner Classes in Java:   Java supports four types of inner classes: Non-static Inner Class:  Associated with an instance of the outer class and can access its members directly. A  non-static inner class  (also called a  regular inner class ) is a class defined  inside another class without the  static  keyword . It has access to the instance variables and methods of the outer class. Example: Static Nested Class:  Similar to static methods; it does not require an instance of the outer class and can only access static members. A  static nested class  is a class defined inside another class using the  static  keyword. Unlike a non-static inner class, it  does not require an instance of the outer class to be created . It behaves like a normal top-level class but is scoped inside the outer class. Example: Method-local Inner Class:  Defined within a method and can access local variables and parameters of the meth...