SlideShare a Scribd company logo
1 of 23
Download to read offline
INNER CLASSES IN JAVA
https://dev.to/dallington256/inner-classes-or-nested-classes-
in-java-4m8d
Objectives
â–ŞWhat are inner classes
â–ŞWhy do we need inner classes
â–ŞAdvantages of using inner classes
â–ŞTypes of inner classes
â–ŞCode examples of each type of inner classes
Definition
An inner class is a class that is declared inside a class or
interface.
Inner classes are used to logically group classes or interfaces in
one place in order to improve readability and maintainability.
Creating an inner class is quite simple. You just need to write a
class within a class. Unlike a class, an inner class can be private
and once you declare an inner class private, it cannot be accessed
from an object outside the class
Syntax of an inner class
class x1 {
// code
class x2{
// code
}
}
Why do we need an inner class
There might be a program where a class must not be accessed
by the other class so in that case, you include it in another
class.
Inner classes are a security mechanism in Java. 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. And this is also used to
access the private members of a class
Advantages of using inner classes
â–ŞBecause inner classes logically group classes and interfaces
in one place only, they improve readability and
maintainability.
â–ŞInner classes are a representation of a particular type of
relationship in that inner class can access all the members
(data members and methods) of an outer class including one
declared private.
▪Minimizes coding efforts since there’s less code to write
thus facilitating code optimization.
Key facts on the relationship between
inner and outer classes
▪Inner and outer classes have access to each other’s private
members.
Within the definition of a method of an inner classes;
âť– It is legal to reference a private instance variable of the
outer class
âť– It is legal to invoke a private method of the outer class
Key facts on the relationship between
inner and outer classes
Within the definition of a method of the outer classes;
âť– It is legal to reference a private instance variable of the
inner class on an object of the inner class.
âť– It is legal to invoke a (non-static) method of the inner class
as long as an object of the inner class is used as a calling
object.
âť– Within the definition of the inner or outer class, the
modifiers public and private are equivalent.
Types of inner classes
There are 4 types of inner classes i.e..
1. Member class (Nested inner class)
2. Static member inner class (Static nested class)
3. Anonymous inner class
4. Local inner class.
1. Member inner class
A member inner class is a class created within a class and
outside a method. A member inner class is non-static.
A member inner class refers directly to its instance variables or
methods defined in its enclosing class. Also because an inner
class is associated with an instance, it cannot define any static
members itself.
Syntax for member inner class
class MainClass{
// code
class InnerClass{
// code
}
Instantiation of a member inner class
Syntax for creating an object of a non-static member
inner class
MainClass m = new MainClass();
MainClass.InnerClass innerObj = m.new InnerClass()
Example
Write simple example to demonstrate member inner class
Dev Link: https://dev.to/dallington256/inner-classes-or-nested-
classes-in-java-4m8d
GitHub Link :https://github.com/DallingtonAsin/BSSE3209.git
2. Static member inner class
A static member inner class is an inner class that is declared static.
Syntax for a static inner class
class MainClass {
// code
static class StaticInnerClass {
// code
}
}
Continue…
In the above code snippet, StaticInnerClass is a static inner class.
This class can’t refer directly to their instance variables or methods
defined in its enclosing class since they use them only by an object
reference.
They are accessed by the use of class name.
Syntax for creating an object of a static inner class
MainClass .StaticInnerClass objectName = new
MainClass.StaticInnerClass();
Example
Write simple example to demonstrate a static member inner class
Dev Link: https://dev.to/dallington256/inner-classes-or-nested-
classes-in-java-4m8d
GitHub Link :https://github.com/DallingtonAsin/BSSE3209.git
Facts
â—ŹCompiling any class in java produces a .class file named
ClassName.class
â—ŹCompiling a class with one (or more) inner classes causes both(or
more) classes to be compiled, and produce two(or more) . class files.
E.g ClassName.class and ClassName$innerClassName.class
3. Anonymous inner class
Anonymous inner class is one that is created for implementing an interface or
extending a class. Thereafter, anonymous class must implement an interface or
extend an abstract class but you don’t use keywords extend or implement to
create anonymous class.
Syntax for anonymous inner class
AnonymousInner an_inner = new AnonymousInner() {
public void my_method() {
// code
}
};
Key facts about anonymous inner class
â–ŞAnonymous inner class cannot have a constructor. Since they have
no name, we can't use them in order to create instances of
anonymous classes. As a result, we have to declare and instantiate
anonymous classes in a single expression at the point of use. We
may either extend an existing class or implement an interface.
â–ŞAnonymous class can access any variables visible to the block
within which anonymous class is declared, including local
variables.
â–ŞAnonymous class can also access methods of a class that contains
it.
Example
Write simple example to demonstrate anonymous inner
class
Dev Link: https://dev.to/dallington256/inner-classes-or-nested-
classes-in-java-4m8d
GitHub Link :https://github.com/DallingtonAsin/BSSE3209.git
4. Local inner classes
A local inner class is one that is defined in a block, which is a group of
zero or more statements between balanced braces. You typically find
local classes defined in the body of a method.
Example
public class Outerclass {
// instance method of the outer class
void my_Method() {
int num = 23;
// method-local inner class
class MethodInner_Demo {
public void print() {
System.out.println("This is method inner class "+num);
}
} // end of inner class
// Accessing the inner class
MethodInner_Demo inner = new MethodInner_Demo();
inner.print();
}
public static void main(String args[]) {
Outerclass outer = new Outerclass();
outer.my_Method();
}
}
Assignment
Use real life examples of your choice to illustrate the use of
following concepts in java programming;
â—ŹMember inner classes;
â—ŹStatic inner classes
â—ŹAnonymous inner classes
â—ŹLocal inner classes
â—ŹRead about helper classes in Java

More Related Content

What's hot

Strings in Java
Strings in JavaStrings in Java
Strings in Java
Abhilash Nair
 
Packages in java
Packages in javaPackages in java
Packages in java
Abhishek Khune
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#
Doncho Minkov
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
Tech_MX
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
kamal kotecha
 
Understanding java streams
Understanding java streamsUnderstanding java streams
Understanding java streams
Shahjahan Samoon
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
Abhilash Nair
 

What's hot (20)

Java string handling
Java string handlingJava string handling
Java string handling
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
 
Packages in java
Packages in javaPackages in java
Packages in java
 
Access specifiers(modifiers) in java
Access specifiers(modifiers) in javaAccess specifiers(modifiers) in java
Access specifiers(modifiers) in java
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#
 
6. static keyword
6. static keyword6. static keyword
6. static keyword
 
Abstraction in java.pptx
Abstraction in java.pptxAbstraction in java.pptx
Abstraction in java.pptx
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
 
Inheritance C#
Inheritance C#Inheritance C#
Inheritance C#
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
Java Basic Oops Concept
Java Basic Oops ConceptJava Basic Oops Concept
Java Basic Oops Concept
 
Java I/o streams
Java I/o streamsJava I/o streams
Java I/o streams
 
Java exception
Java exception Java exception
Java exception
 
Understanding java streams
Understanding java streamsUnderstanding java streams
Understanding java streams
 
Java static keyword
Java static keywordJava static keyword
Java static keyword
 
Object Oriented Programing JAVA presentaion
Object Oriented Programing JAVA presentaionObject Oriented Programing JAVA presentaion
Object Oriented Programing JAVA presentaion
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
 
Oops concept on c#
Oops concept on c#Oops concept on c#
Oops concept on c#
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
 

Similar to Inner Classes in Java

Inner Classes & Multi Threading in JAVA
Inner Classes & Multi Threading in JAVAInner Classes & Multi Threading in JAVA
Inner Classes & Multi Threading in JAVA
Tech_MX
 
Javasession8
Javasession8Javasession8
Javasession8
Rajeev Kumar
 
Inner Classes
Inner ClassesInner Classes
Inner Classes
parag
 
[圣思园][Java SE]Inner class
[圣思园][Java SE]Inner class[圣思园][Java SE]Inner class
[圣思园][Java SE]Inner class
ArBing Xie
 
Object and Classes in Java
Object and Classes in JavaObject and Classes in Java
Object and Classes in Java
backdoor
 
Inner classes9 cm604.28
Inner classes9 cm604.28Inner classes9 cm604.28
Inner classes9 cm604.28
myrajendra
 

Similar to Inner Classes in Java (20)

Inner class
Inner classInner class
Inner class
 
Inner Classes & Multi Threading in JAVA
Inner Classes & Multi Threading in JAVAInner Classes & Multi Threading in JAVA
Inner Classes & Multi Threading in JAVA
 
Nested class in java
Nested class in javaNested class in java
Nested class in java
 
Object oriented programming CLASSES-AND-OBJECTS.pptx
Object oriented programming CLASSES-AND-OBJECTS.pptxObject oriented programming CLASSES-AND-OBJECTS.pptx
Object oriented programming CLASSES-AND-OBJECTS.pptx
 
Javasession8
Javasession8Javasession8
Javasession8
 
types of classes in java
types of classes in javatypes of classes in java
types of classes in java
 
A1771937735_21789_14_2018__16_ Nested Classes.ppt
A1771937735_21789_14_2018__16_ Nested Classes.pptA1771937735_21789_14_2018__16_ Nested Classes.ppt
A1771937735_21789_14_2018__16_ Nested Classes.ppt
 
Nested classes in java
Nested classes in javaNested classes in java
Nested classes in java
 
Java Nested class Concept
Java Nested class ConceptJava Nested class Concept
Java Nested class Concept
 
Nested classes in java
Nested classes in javaNested classes in java
Nested classes in java
 
Inner class
Inner classInner class
Inner class
 
Inner Classes
Inner ClassesInner Classes
Inner Classes
 
[圣思园][Java SE]Inner class
[圣思园][Java SE]Inner class[圣思园][Java SE]Inner class
[圣思园][Java SE]Inner class
 
Inner class
Inner classInner class
Inner class
 
Lecture 10
Lecture 10Lecture 10
Lecture 10
 
Object and Classes in Java
Object and Classes in JavaObject and Classes in Java
Object and Classes in Java
 
Inner classes
Inner classesInner classes
Inner classes
 
Java Inner Class
Java Inner ClassJava Inner Class
Java Inner Class
 
Nested class
Nested classNested class
Nested class
 
Inner classes9 cm604.28
Inner classes9 cm604.28Inner classes9 cm604.28
Inner classes9 cm604.28
 

Recently uploaded

%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 

Recently uploaded (20)

Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 

Inner Classes in Java

  • 1. INNER CLASSES IN JAVA https://dev.to/dallington256/inner-classes-or-nested-classes- in-java-4m8d
  • 2. Objectives â–ŞWhat are inner classes â–ŞWhy do we need inner classes â–ŞAdvantages of using inner classes â–ŞTypes of inner classes â–ŞCode examples of each type of inner classes
  • 3. Definition An inner class is a class that is declared inside a class or interface. Inner classes are used to logically group classes or interfaces in one place in order to improve readability and maintainability. Creating an inner class is quite simple. You just need to write a class within a class. Unlike a class, an inner class can be private and once you declare an inner class private, it cannot be accessed from an object outside the class
  • 4. Syntax of an inner class class x1 { // code class x2{ // code } }
  • 5. Why do we need an inner class There might be a program where a class must not be accessed by the other class so in that case, you include it in another class. Inner classes are a security mechanism in Java. 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. And this is also used to access the private members of a class
  • 6. Advantages of using inner classes â–ŞBecause inner classes logically group classes and interfaces in one place only, they improve readability and maintainability. â–ŞInner classes are a representation of a particular type of relationship in that inner class can access all the members (data members and methods) of an outer class including one declared private. â–ŞMinimizes coding efforts since there’s less code to write thus facilitating code optimization.
  • 7. Key facts on the relationship between inner and outer classes â–ŞInner and outer classes have access to each other’s private members. Within the definition of a method of an inner classes; âť– It is legal to reference a private instance variable of the outer class âť– It is legal to invoke a private method of the outer class
  • 8. Key facts on the relationship between inner and outer classes Within the definition of a method of the outer classes; âť– It is legal to reference a private instance variable of the inner class on an object of the inner class. âť– It is legal to invoke a (non-static) method of the inner class as long as an object of the inner class is used as a calling object. âť– Within the definition of the inner or outer class, the modifiers public and private are equivalent.
  • 9. Types of inner classes There are 4 types of inner classes i.e.. 1. Member class (Nested inner class) 2. Static member inner class (Static nested class) 3. Anonymous inner class 4. Local inner class.
  • 10. 1. Member inner class A member inner class is a class created within a class and outside a method. A member inner class is non-static. A member inner class refers directly to its instance variables or methods defined in its enclosing class. Also because an inner class is associated with an instance, it cannot define any static members itself.
  • 11. Syntax for member inner class class MainClass{ // code class InnerClass{ // code }
  • 12. Instantiation of a member inner class Syntax for creating an object of a non-static member inner class MainClass m = new MainClass(); MainClass.InnerClass innerObj = m.new InnerClass()
  • 13. Example Write simple example to demonstrate member inner class Dev Link: https://dev.to/dallington256/inner-classes-or-nested- classes-in-java-4m8d GitHub Link :https://github.com/DallingtonAsin/BSSE3209.git
  • 14. 2. Static member inner class A static member inner class is an inner class that is declared static. Syntax for a static inner class class MainClass { // code static class StaticInnerClass { // code } }
  • 15. Continue… In the above code snippet, StaticInnerClass is a static inner class. This class can’t refer directly to their instance variables or methods defined in its enclosing class since they use them only by an object reference. They are accessed by the use of class name. Syntax for creating an object of a static inner class MainClass .StaticInnerClass objectName = new MainClass.StaticInnerClass();
  • 16. Example Write simple example to demonstrate a static member inner class Dev Link: https://dev.to/dallington256/inner-classes-or-nested- classes-in-java-4m8d GitHub Link :https://github.com/DallingtonAsin/BSSE3209.git
  • 17. Facts â—ŹCompiling any class in java produces a .class file named ClassName.class â—ŹCompiling a class with one (or more) inner classes causes both(or more) classes to be compiled, and produce two(or more) . class files. E.g ClassName.class and ClassName$innerClassName.class
  • 18. 3. Anonymous inner class Anonymous inner class is one that is created for implementing an interface or extending a class. Thereafter, anonymous class must implement an interface or extend an abstract class but you don’t use keywords extend or implement to create anonymous class. Syntax for anonymous inner class AnonymousInner an_inner = new AnonymousInner() { public void my_method() { // code } };
  • 19. Key facts about anonymous inner class â–ŞAnonymous inner class cannot have a constructor. Since they have no name, we can't use them in order to create instances of anonymous classes. As a result, we have to declare and instantiate anonymous classes in a single expression at the point of use. We may either extend an existing class or implement an interface. â–ŞAnonymous class can access any variables visible to the block within which anonymous class is declared, including local variables. â–ŞAnonymous class can also access methods of a class that contains it.
  • 20. Example Write simple example to demonstrate anonymous inner class Dev Link: https://dev.to/dallington256/inner-classes-or-nested- classes-in-java-4m8d GitHub Link :https://github.com/DallingtonAsin/BSSE3209.git
  • 21. 4. Local inner classes A local inner class is one that is defined in a block, which is a group of zero or more statements between balanced braces. You typically find local classes defined in the body of a method.
  • 22. Example public class Outerclass { // instance method of the outer class void my_Method() { int num = 23; // method-local inner class class MethodInner_Demo { public void print() { System.out.println("This is method inner class "+num); } } // end of inner class // Accessing the inner class MethodInner_Demo inner = new MethodInner_Demo(); inner.print(); } public static void main(String args[]) { Outerclass outer = new Outerclass(); outer.my_Method(); } }
  • 23. Assignment Use real life examples of your choice to illustrate the use of following concepts in java programming; â—ŹMember inner classes; â—ŹStatic inner classes â—ŹAnonymous inner classes â—ŹLocal inner classes â—ŹRead about helper classes in Java