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


Public class Outer{
   class Inner{
Updated on 19-Feb-2020 07:46:58