What are inner classes in Java?

Java 8Object Oriented ProgrammingProgramming

Java allows writing classes within classes and the class which is written inside another is known as inner class.

  • Inner classes are a kind of security mechanism in Java.
  • You can declare an inner class private once you do it cannot be accessed from an object outside the class.

Java supports three kinds of inner classes.

  • Inner Class
  • Method-local Inner Class
  • Anonymous Inner Class

Example

Public class Outer{
   class Inner{
   }
}
raja
Published on 08-Jan-2018 07:09:10
Advertisements