SlideShare a Scribd company logo
types of classes in java
Nested Classes
 Writing a class within another is allowed
in Java. The class written within is called
the nested class, and the class that
holds the inner class is called the outer
class.
Nested Classes
The syntax to write a nested class is given
below. Here the class Outer_Demo is the
outer class and the class Nested_Demo is
the nested class.
Types Nested Classes
 Non-static nested classes:
 These are the non-static members of a
class.
 Static nested classes:
 These are the static members of a class.
Types Nested Classes
Inner Classes
 Inner classes are of three types
depending on how and where you define
them. They are:
 Inner Class
 Method-local Inner Classlass
 Anonymous Inner Class
Inner Classes
 Creating an inner class is quite simple. You
just need to write a class within a class
Inner Classes
Inner Classes
 Here you can observe that Outer_Demo is
the outer class,Inner_Demo is the inner
class, display_Inner() is the method inside
which we are instantiating the inner class,
and this method is invoked from
the main method
Accessing private Members of
class
 Inner classes are also used to access the
private members of a class.
 To instantiate the inner class, initially you
have to instantiate the outer class.
Thereafter, using the object of the outer
class, you can instantiate the inner class as
shown below.
Accessing private Members of
class
Static Nested Classes
 A static inner class is a nested class
which is a static member of the outer
class. It can be accessed without
instantiating the outer class, using
other static members. Just like static
members, a static nested class does not
have access to the instance variables
and methods of the outer class. The
syntax of static nested class is as
follows:
Syntax for Static Nested
Classes
Static Nested Classes
 Instantiating a static nested class is a bit
different from instantiating an inner
class. The following program shows how
to use a static nested class.
Static Nested Classes

More Related Content

PPTX
Nested classes in java
PPTX
Inner classes
PPT
L5 classes, objects, nested and inner class
PPTX
Inner class
PPTX
Java Inner Class
DOCX
Nested classes in java
PDF
Inner Classes in Java
PPT
Inner classes ,annoumous and outer classes in java
Nested classes in java
Inner classes
L5 classes, objects, nested and inner class
Inner class
Java Inner Class
Nested classes in java
Inner Classes in Java
Inner classes ,annoumous and outer classes in java

What's hot (20)

PPTX
Inner Classes & Multi Threading in JAVA
PDF
Classes and Nested Classes in Java
PPTX
Java- Nested Classes
PPT
Inner classes9 cm604.28
DOCX
Nested class in java
PPTX
Inner classes in java
PDF
Java Inner Classes
PPTX
C# Inheritance
PPTX
Java(inheritance)
PPT
encapsulation and abstraction
PPT
Chap02
PPTX
Introducing classes
PPTX
C# classes objects
PPT
Java inheritance
PPTX
Access modifiers in java
PPTX
Java static keyword
PPT
Java: Inheritance
PPTX
Inheritance in JAVA PPT
ODP
Oop scala
PPTX
Inheritance and its types In Java
Inner Classes & Multi Threading in JAVA
Classes and Nested Classes in Java
Java- Nested Classes
Inner classes9 cm604.28
Nested class in java
Inner classes in java
Java Inner Classes
C# Inheritance
Java(inheritance)
encapsulation and abstraction
Chap02
Introducing classes
C# classes objects
Java inheritance
Access modifiers in java
Java static keyword
Java: Inheritance
Inheritance in JAVA PPT
Oop scala
Inheritance and its types In Java
Ad

Similar to types of classes in java (20)

PPT
A1771937735_21789_14_2018__16_ Nested Classes.ppt
PPTX
Java Nested class Concept
PPTX
Inner class
PPTX
Java Programming inner and Nested classes.pptx
PPTX
Java Nested classes, static class and methods, nested blocks_Inner_Classes.pptx
PPTX
WINSEMFRE2024-25_CSE2005_ETH_AP2024255000715_2025-03-18_Reference-Material-I....
PPTX
Nested class
PPTX
Javasession8
PPTX
Static Members-Java.pptx
PPTX
Object oriented programming CLASSES-AND-OBJECTS.pptx
PPTX
Inner classes
PPTX
[Java] #8 String and Inner Class
PPTX
Session 21 - Inner Classes
PDF
Class method object
PDF
Java Inner Classes
PDF
Classes in Java great learning.pdf
PPT
Inner Classes
PDF
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
PPSX
Inner Classes
PPTX
UNIT - IIInew.pptx
A1771937735_21789_14_2018__16_ Nested Classes.ppt
Java Nested class Concept
Inner class
Java Programming inner and Nested classes.pptx
Java Nested classes, static class and methods, nested blocks_Inner_Classes.pptx
WINSEMFRE2024-25_CSE2005_ETH_AP2024255000715_2025-03-18_Reference-Material-I....
Nested class
Javasession8
Static Members-Java.pptx
Object oriented programming CLASSES-AND-OBJECTS.pptx
Inner classes
[Java] #8 String and Inner Class
Session 21 - Inner Classes
Class method object
Java Inner Classes
Classes in Java great learning.pdf
Inner Classes
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
Inner Classes
UNIT - IIInew.pptx
Ad

Recently uploaded (20)

PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
Essential Infomation Tech presentation.pptx
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
history of c programming in notes for students .pptx
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Nekopoi APK 2025 free lastest update
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Essential Infomation Tech presentation.pptx
Odoo Companies in India – Driving Business Transformation.pdf
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
history of c programming in notes for students .pptx
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Understanding Forklifts - TECH EHS Solution
CHAPTER 2 - PM Management and IT Context
wealthsignaloriginal-com-DS-text-... (1).pdf
Design an Analysis of Algorithms I-SECS-1021-03
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Softaken Excel to vCard Converter Software.pdf
Upgrade and Innovation Strategies for SAP ERP Customers
Nekopoi APK 2025 free lastest update
Reimagine Home Health with the Power of Agentic AI​
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
How to Migrate SBCGlobal Email to Yahoo Easily
2025 Textile ERP Trends: SAP, Odoo & Oracle

types of classes in java

  • 2. Nested Classes  Writing a class within another is allowed in Java. The class written within is called the nested class, and the class that holds the inner class is called the outer class.
  • 3. Nested Classes The syntax to write a nested class is given below. Here the class Outer_Demo is the outer class and the class Nested_Demo is the nested class.
  • 4. Types Nested Classes  Non-static nested classes:  These are the non-static members of a class.  Static nested classes:  These are the static members of a class.
  • 6. Inner Classes  Inner classes are of three types depending on how and where you define them. They are:  Inner Class  Method-local Inner Classlass  Anonymous Inner Class
  • 7. Inner Classes  Creating an inner class is quite simple. You just need to write a class within a class
  • 9. Inner Classes  Here you can observe that Outer_Demo is the outer class,Inner_Demo is the inner class, display_Inner() is the method inside which we are instantiating the inner class, and this method is invoked from the main method
  • 10. Accessing private Members of class  Inner classes are also used to access the private members of a class.  To instantiate the inner class, initially you have to instantiate the outer class. Thereafter, using the object of the outer class, you can instantiate the inner class as shown below.
  • 12. Static Nested Classes  A static inner class is a nested class which is a static member of the outer class. It can be accessed without instantiating the outer class, using other static members. Just like static members, a static nested class does not have access to the instance variables and methods of the outer class. The syntax of static nested class is as follows:
  • 13. Syntax for Static Nested Classes
  • 14. Static Nested Classes  Instantiating a static nested class is a bit different from instantiating an inner class. The following program shows how to use a static nested class.

Editor's Notes

  • #7: NOTE: We know a class cannot be associated with the access modifier private, but if we have the class as a member of other class, then the inner class can be made private. 
  • #8: NOTE: We know a class cannot be associated with the access modifier private, but if we have the class as a member of other class, then the inner class can be made private.