What are inner classes in Java?

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


Public class Outer{
   class Inner{