Local inner class

  • Eclipse: Oxygen
  • Java: 1.8

Working with the local inner class which is defined or structured inside the outer class is shown here. Here the example of door and lock is shown as a real-life example.

In Java, we can write a class within a method it is called a local inner type. Like local variables, the scope of the inner class is restricted inside the method. If you want to invoke the methods of a local inner class, you must instantiate this class inside the method.

The advantage of such a case is the inner class is completely hidden from the outside world. The following program shows how to use an inner class of method.

 

Output

true

 

Output

true

Contributed by: Poonam Tomar


VIEW COURSES

Buy me a coffee!

 

PayTM QR (INDIA)

  • Get video tutorials
  • Project files set
  • Get┬áCertified

Leave a Reply

avatar
  Subscribe  
Notify of
Close Menu