0% found this document useful (0 votes)
6 views11 pages

Inner Class Java PPT Krisha

An inner class in Java is a class defined within another class, allowing access to the outer class's members and enhancing encapsulation. There are four types of inner classes: Member Inner Class, Static Nested Class, Anonymous Inner Class, and Local Inner Class, each with distinct characteristics and use cases. Advantages of inner classes include logical grouping, direct access to outer class members, code optimization, and improved encapsulation.

Uploaded by

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

Inner Class Java PPT Krisha

An inner class in Java is a class defined within another class, allowing access to the outer class's members and enhancing encapsulation. There are four types of inner classes: Member Inner Class, Static Nested Class, Anonymous Inner Class, and Local Inner Class, each with distinct characteristics and use cases. Advantages of inner classes include logical grouping, direct access to outer class members, code optimization, and improved encapsulation.

Uploaded by

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

INNER CLASS

BY : K R I S H A A M B A L I YA ( 1 2 3 0 2 0 8 0 5 0 1 0 2 7 )
K R I S H N A R AT H O D ( 1 2 3 0 2 0 8 0 5 0 1 0 2 8 )
WHAT IS INNER CLASS?

• In Java, an inner class is a class defined within


another class. It is also known as a nested
class. Inner classes can access all the members
(including private ones) of the outer class. They
are often used to logically group classes that are
only used in one place and to increase
encapsulation.
BASIC EXAMPLE
EXPLANATION
TYPES OF INNER CLASS

• Member Inner Class


• Non-static, tied to outer class instances.
• Static Nested Class
• Static, linked to the outer class.
• Anonymous Inner Class
• Inline, nameless implementations.
• Local Inner Class
• Declared inside methods or blocks.
MEMBER INNER CLASS

• A member inner
class is defined
inside a class
but outside any
method.
• It can access all
members
(including private)
of the outer class.
• It is associated
with an instance
of the outer class.
STATIC NESTED CLASS

• Defined with the


static keyword
inside the outer
class.
• It cannot access
non-static
members of the
outer class directly.
• Can be instantiated
without creating
an object of the
outer class.
ANONYMOUS INNER CLASS

• A class that
doesn’t have a
name and is used
to provide an
implementation
of an interface
or extend a
class on the spot.
• Often used in
event handling
or thread
creation.
LOCAL INNER CLASS

• Defined inside a
method or a block.
• Can access final or
effectively final
variables from the
enclosing method.
• Its scope is limited
to the block/method
in which it's defined.
ADVANTAGES

• ✅ Logical Grouping: Groups related classes


together for better structure.
• ✅ Access to Outer Class Members: Can access
private members of the outer class directly.
• ✅ Code Optimization: Anonymous classes
reduce boilerplate for simple use cases (e.g.,
event handling).
• ✅ Better Encapsulation: Keeps helper classes
hidden and secure within the outer class.

You might also like