Basic of Java

OOPs Concepts

Java String

Java Regex

Exception Handling

Java Inner Class

Java Local inner class

A class i.e. created inside a method is called local inner class in java. If you want to invoke the methods of local inner class, you must instantiate this class inside the method.

Java local inner class example

Flash Soon


Internal class generated by the compiler

In such case, compiler creates a class named Simple$1Local that have the reference of the outer class.

Flash Soon

Rule: Local variable can't be private, public or protected.

Rules for Java Local Inner class

1) Local inner class cannot be invoked from outside the method.

2) Local inner class cannot access non-final local variable till JDK 1.7. Since JDK 1.8, it is possible to access the non-final local variable in local inner class.

Example of local inner class with local variable

Flash Soon


Copyright 2017 Design& Development