Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
177 views6 pages

Inner Class

Java inner classes are classes declared within other classes or interfaces. They allow a class to access all members of the outer class, including private members. Inner classes make code more readable and maintainable by logically grouping related classes together. There are two types of nested classes: non-static nested classes, also called inner classes, and static nested classes. Non-static nested classes include member inner classes, anonymous inner classes, and local inner classes.

Uploaded by

N K
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
177 views6 pages

Inner Class

Java inner classes are classes declared within other classes or interfaces. They allow a class to access all members of the outer class, including private members. Inner classes make code more readable and maintainable by logically grouping related classes together. There are two types of nested classes: non-static nested classes, also called inner classes, and static nested classes. Non-static nested classes include member inner classes, anonymous inner classes, and local inner classes.

Uploaded by

N K
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

INNER CLASS

• Java inner class or nested class is a class which is declared inside the class or interface.
• We use inner classes to logically group classes and interfaces in one place so that it can be more readable
and maintainable.
• Additionally, it can access all the members of outer class including private data members and methods.
Syntax of Inner class
class Java_Outer_class{
//code
class Java_Inner_class
{ //code
} }
Advantage of java inner classes

• 1) Nested classes represent a special type of relationship that is it can access all the
members (data members and methods) of outer class including private.

• 2) Nested classes are used to develop more readable and maintainable code because
it logically group classes and interfaces in one place only.

• 3) Code Optimization: It requires less code to write.


• Difference between nested class and inner class in Java
Inner class is a part of nested class. Non-static nested classes are known as inner classes.

• Types of Nested classes


• There are two types of nested classes non-static and static nested classes. The non-static
nested classes are also known as inner classes.
• Non-static nested class (inner class)
o Member inner class
o Anonymous inner class
o Local inner class
• Static nested class
Type Description

Member Inner Class A class created within class and outside method.

A class created for implementing interface or


Anonymous Inner Class extending class. Its name is decided by the java
compiler.

Local Inner Class A class created within method.

Static Nested Class A static class created within class.


THANK YOU

You might also like