SlideShare a Scribd company logo
1 of 8
Download to read offline
youtube:Zooming | https://github.com/Soba-Arjun/
youtube:Zooming | https://github.com/Soba-Arjun/
Inner Class
 Inner class means one class which is a member of another class.
 There are basically four types of inner classes in java.
 Nested Inner class.
 Method Local inner classes.
 Anonymous inner classes.
 Static nested classes.
youtube:Zooming | https://github.com/Soba-Arjun/
Nested Inner Class
class Outer {
// Simple nested inner class
class Inner {
public void show() {
System.out.println(“nested inner class");
}
}
}
class Main {
public static void main(String[] args) {
Outer.Inner in = new Outer().new Inner();
in.show();
}
}
• we can’t have static method in a
nested inner class.
• Because an inner class is implicitly
associated with an object of its
outer class so it cannot define any
static method for itself
youtube:Zooming | https://github.com/Soba-Arjun/
Static Nested Class
Static nested classes are not
technically an inner class. They
are like a static member of outer
class.
class Outer {
private static void outerMethod() {
System.out.println("inside outerMethod");
}
// A static inner class
static class Inner {
public static void main(String[] args) {
System.out.println("inside inner class Method");
outerMethod();
}
}
} inside inner class
Method inside outerMethod
youtube:Zooming | https://github.com/Soba-Arjun/
Method Local Inner Class
• Inner class can be declared
within the method of an outer
class.
class Outer {
void outerMethod() {
System.out.println("inside outerMethod");
// Inner class is local to outerMethod()
class Inner {
void innerMethod() {
System.out.println("inside innerMethod");
}
}
Inner y = new Inner();
y.innerMethod();
}
}
class MethodDemo {
public static void main(String[] args) {
Outer x = new Outer();
x.outerMethod();
}
}
youtube:Zooming | https://github.com/Soba-Arjun/
Method Local Inner Class
• Method Local inner classes
can’t use local variable of outer
method until that local variable
is not declared as final.
class Outer {
void outerMethod() {
int x = 98;
System.out.println("inside outerMethod");
class Inner {
void innerMethod() {
System.out.println("x= "+x);
}
}
Inner y = new Inner();
y.innerMethod();
}
}
class MethodLocalVariableDemo {
public static void main(String[] args) {
Outer x=new Outer();
x.outerMethod();
}
}
local variable x is accessed from within inner class;
needs to be declared final
youtube:Zooming | https://github.com/Soba-Arjun/
Method Local Inner Class
• Method Local inner classes
can’t use local variable of outer
method until that local variable
is not declared as final.
class Outer {
void outerMethod() {
final int x = 98;
System.out.println("inside outerMethod");
class Inner {
void innerMethod() {
System.out.println("x= "+x);
}
}
Inner y = new Inner();
y.innerMethod();
}
}
class MethodLocalVariableDemo {
public static void main(String[] args) {
Outer x=new Outer();
x.outerMethod();
}
}
Inside outerMethod
X = 98
youtube:Zooming | https://github.com/Soba-Arjun/
Anonymous Inner Class
Anonymous inner classes are
declared without any name at all.
Super class
Sub class
class Demo {
void show() {
System.out.println(“super class");
}
}
class Flavor1Demo {
// An anonymous class with Demo as base class
static Demo d = new Demo() {
void show() {
super.show();
System.out.println(“sub class");
}
};
public static void main(String[] args){
d.show();
}
}

More Related Content

What's hot

Java Inner Class
Java Inner ClassJava Inner Class
Java Inner ClassDeeptiJava
 
L5 classes, objects, nested and inner class
L5 classes, objects, nested and inner classL5 classes, objects, nested and inner class
L5 classes, objects, nested and inner classteach4uin
 
Classes and objects
Classes and objectsClasses and objects
Classes and objectsAnil Kumar
 
Week9 Intro to classes and objects in Java
Week9 Intro to classes and objects in JavaWeek9 Intro to classes and objects in Java
Week9 Intro to classes and objects in Javakjkleindorfer
 
Week10 packages using objects in objects
Week10 packages using objects in objectsWeek10 packages using objects in objects
Week10 packages using objects in objectskjkleindorfer
 
Logic and Coding of Java Interfaces & Swing Applications
Logic and Coding of Java Interfaces & Swing ApplicationsLogic and Coding of Java Interfaces & Swing Applications
Logic and Coding of Java Interfaces & Swing Applicationskjkleindorfer
 
Concept of Object-Oriented in C++
Concept of Object-Oriented in C++Concept of Object-Oriented in C++
Concept of Object-Oriented in C++Abdullah Jan
 
Object as function argument , friend and static function by shahzad younas
Object as function argument , friend and static function by shahzad younasObject as function argument , friend and static function by shahzad younas
Object as function argument , friend and static function by shahzad younasShahzad Younas
 
friend function(c++)
friend function(c++)friend function(c++)
friend function(c++)Ritika Sharma
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteTushar B Kute
 
Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
Unit 2-data types,Variables,Operators,Conitionals,loops and arraysUnit 2-data types,Variables,Operators,Conitionals,loops and arrays
Unit 2-data types,Variables,Operators,Conitionals,loops and arraysDevaKumari Vijay
 
Pi j3.2 polymorphism
Pi j3.2 polymorphismPi j3.2 polymorphism
Pi j3.2 polymorphismmcollison
 

What's hot (20)

Java Inner Class
Java Inner ClassJava Inner Class
Java Inner Class
 
L5 classes, objects, nested and inner class
L5 classes, objects, nested and inner classL5 classes, objects, nested and inner class
L5 classes, objects, nested and inner class
 
Inner classes
Inner classesInner classes
Inner classes
 
Unit3 part2-inheritance
Unit3 part2-inheritanceUnit3 part2-inheritance
Unit3 part2-inheritance
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Week9 Intro to classes and objects in Java
Week9 Intro to classes and objects in JavaWeek9 Intro to classes and objects in Java
Week9 Intro to classes and objects in Java
 
Week10 packages using objects in objects
Week10 packages using objects in objectsWeek10 packages using objects in objects
Week10 packages using objects in objects
 
Unit3 part1-class
Unit3 part1-classUnit3 part1-class
Unit3 part1-class
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
Logic and Coding of Java Interfaces & Swing Applications
Logic and Coding of Java Interfaces & Swing ApplicationsLogic and Coding of Java Interfaces & Swing Applications
Logic and Coding of Java Interfaces & Swing Applications
 
Concept of Object-Oriented in C++
Concept of Object-Oriented in C++Concept of Object-Oriented in C++
Concept of Object-Oriented in C++
 
class c++
class c++class c++
class c++
 
C# Access modifiers
C# Access modifiersC# Access modifiers
C# Access modifiers
 
Write First C++ class
Write First C++ classWrite First C++ class
Write First C++ class
 
Object as function argument , friend and static function by shahzad younas
Object as function argument , friend and static function by shahzad younasObject as function argument , friend and static function by shahzad younas
Object as function argument , friend and static function by shahzad younas
 
Classes and objects in java
Classes and objects in javaClasses and objects in java
Classes and objects in java
 
friend function(c++)
friend function(c++)friend function(c++)
friend function(c++)
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
 
Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
Unit 2-data types,Variables,Operators,Conitionals,loops and arraysUnit 2-data types,Variables,Operators,Conitionals,loops and arrays
Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
 
Pi j3.2 polymorphism
Pi j3.2 polymorphismPi j3.2 polymorphism
Pi j3.2 polymorphism
 

Similar to Java Inner Classes

Similar to Java Inner Classes (20)

Session 21 - Inner Classes
Session 21 - Inner ClassesSession 21 - Inner Classes
Session 21 - Inner Classes
 
Inner Classes
Inner Classes Inner Classes
Inner Classes
 
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
 
Static Members-Java.pptx
Static Members-Java.pptxStatic Members-Java.pptx
Static Members-Java.pptx
 
Inner classes in java
Inner classes in javaInner classes in java
Inner classes in java
 
Nested class
Nested classNested class
Nested class
 
OOPs & Inheritance Notes
OOPs & Inheritance NotesOOPs & Inheritance Notes
OOPs & Inheritance Notes
 
types of classes in java
types of classes in javatypes of classes in java
types of classes in java
 
Nested class in java
Nested class in javaNested class in java
Nested class in java
 
UNIT 5.pptx
UNIT 5.pptxUNIT 5.pptx
UNIT 5.pptx
 
Class introduction in java
Class introduction in javaClass introduction in java
Class introduction in java
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
 
nested_Object as Parameter & Recursion_Later_commamd.pptx
nested_Object as Parameter  & Recursion_Later_commamd.pptxnested_Object as Parameter  & Recursion_Later_commamd.pptx
nested_Object as Parameter & Recursion_Later_commamd.pptx
 
[圣思园][Java SE]Inner class
[圣思园][Java SE]Inner class[圣思园][Java SE]Inner class
[圣思园][Java SE]Inner class
 
Inner class
Inner classInner class
Inner class
 
Inner Classes
Inner ClassesInner Classes
Inner Classes
 
Closer look at classes
Closer look at classesCloser look at classes
Closer look at classes
 
Developing Applications for Android - Lecture#2
Developing Applications for Android - Lecture#2Developing Applications for Android - Lecture#2
Developing Applications for Android - Lecture#2
 
Inner Classes in Java
Inner Classes in JavaInner Classes in Java
Inner Classes in Java
 

More from Soba Arjun

Java interview questions
Java interview questionsJava interview questions
Java interview questionsSoba Arjun
 
Java modifiers
Java modifiersJava modifiers
Java modifiersSoba Arjun
 
Java variable types
Java variable typesJava variable types
Java variable typesSoba Arjun
 
Java basic datatypes
Java basic datatypesJava basic datatypes
Java basic datatypesSoba Arjun
 
Dbms interview questions
Dbms interview questionsDbms interview questions
Dbms interview questionsSoba Arjun
 
C interview questions
C interview questionsC interview questions
C interview questionsSoba Arjun
 
Technical interview questions
Technical interview questionsTechnical interview questions
Technical interview questionsSoba Arjun
 
Php interview questions with answer
Php interview questions with answerPhp interview questions with answer
Php interview questions with answerSoba Arjun
 
Computer Memory Types - Primary Memory - Secondary Memory
Computer Memory Types - Primary Memory - Secondary MemoryComputer Memory Types - Primary Memory - Secondary Memory
Computer Memory Types - Primary Memory - Secondary MemorySoba Arjun
 
Birds sanctuaries
Birds sanctuariesBirds sanctuaries
Birds sanctuariesSoba Arjun
 
Important operating systems
Important operating systemsImportant operating systems
Important operating systemsSoba Arjun
 
Important branches of science
Important branches of scienceImportant branches of science
Important branches of scienceSoba Arjun
 
Important file extensions
Important file extensionsImportant file extensions
Important file extensionsSoba Arjun
 
Java Abstraction
Java AbstractionJava Abstraction
Java AbstractionSoba Arjun
 
Java Polymorphism
Java PolymorphismJava Polymorphism
Java PolymorphismSoba Arjun
 
Java Overriding
Java OverridingJava Overriding
Java OverridingSoba Arjun
 
java Exception
java Exceptionjava Exception
java ExceptionSoba Arjun
 
java Inheritance
java Inheritancejava Inheritance
java InheritanceSoba Arjun
 
Major tribes of india
Major tribes of indiaMajor tribes of india
Major tribes of indiaSoba Arjun
 

More from Soba Arjun (20)

Java interview questions
Java interview questionsJava interview questions
Java interview questions
 
Java modifiers
Java modifiersJava modifiers
Java modifiers
 
Java variable types
Java variable typesJava variable types
Java variable types
 
Java basic datatypes
Java basic datatypesJava basic datatypes
Java basic datatypes
 
Dbms interview questions
Dbms interview questionsDbms interview questions
Dbms interview questions
 
C interview questions
C interview questionsC interview questions
C interview questions
 
Technical interview questions
Technical interview questionsTechnical interview questions
Technical interview questions
 
Php interview questions with answer
Php interview questions with answerPhp interview questions with answer
Php interview questions with answer
 
Computer Memory Types - Primary Memory - Secondary Memory
Computer Memory Types - Primary Memory - Secondary MemoryComputer Memory Types - Primary Memory - Secondary Memory
Computer Memory Types - Primary Memory - Secondary Memory
 
Birds sanctuaries
Birds sanctuariesBirds sanctuaries
Birds sanctuaries
 
Important operating systems
Important operating systemsImportant operating systems
Important operating systems
 
Important branches of science
Important branches of scienceImportant branches of science
Important branches of science
 
Important file extensions
Important file extensionsImportant file extensions
Important file extensions
 
Java Abstraction
Java AbstractionJava Abstraction
Java Abstraction
 
Java Polymorphism
Java PolymorphismJava Polymorphism
Java Polymorphism
 
Java Overriding
Java OverridingJava Overriding
Java Overriding
 
java Exception
java Exceptionjava Exception
java Exception
 
Java Methods
Java MethodsJava Methods
Java Methods
 
java Inheritance
java Inheritancejava Inheritance
java Inheritance
 
Major tribes of india
Major tribes of indiaMajor tribes of india
Major tribes of india
 

Recently uploaded

Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxsqpmdrvczh
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 

Recently uploaded (20)

Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 

Java Inner Classes

  • 2. youtube:Zooming | https://github.com/Soba-Arjun/ Inner Class  Inner class means one class which is a member of another class.  There are basically four types of inner classes in java.  Nested Inner class.  Method Local inner classes.  Anonymous inner classes.  Static nested classes.
  • 3. youtube:Zooming | https://github.com/Soba-Arjun/ Nested Inner Class class Outer { // Simple nested inner class class Inner { public void show() { System.out.println(“nested inner class"); } } } class Main { public static void main(String[] args) { Outer.Inner in = new Outer().new Inner(); in.show(); } } • we can’t have static method in a nested inner class. • Because an inner class is implicitly associated with an object of its outer class so it cannot define any static method for itself
  • 4. youtube:Zooming | https://github.com/Soba-Arjun/ Static Nested Class Static nested classes are not technically an inner class. They are like a static member of outer class. class Outer { private static void outerMethod() { System.out.println("inside outerMethod"); } // A static inner class static class Inner { public static void main(String[] args) { System.out.println("inside inner class Method"); outerMethod(); } } } inside inner class Method inside outerMethod
  • 5. youtube:Zooming | https://github.com/Soba-Arjun/ Method Local Inner Class • Inner class can be declared within the method of an outer class. class Outer { void outerMethod() { System.out.println("inside outerMethod"); // Inner class is local to outerMethod() class Inner { void innerMethod() { System.out.println("inside innerMethod"); } } Inner y = new Inner(); y.innerMethod(); } } class MethodDemo { public static void main(String[] args) { Outer x = new Outer(); x.outerMethod(); } }
  • 6. youtube:Zooming | https://github.com/Soba-Arjun/ Method Local Inner Class • Method Local inner classes can’t use local variable of outer method until that local variable is not declared as final. class Outer { void outerMethod() { int x = 98; System.out.println("inside outerMethod"); class Inner { void innerMethod() { System.out.println("x= "+x); } } Inner y = new Inner(); y.innerMethod(); } } class MethodLocalVariableDemo { public static void main(String[] args) { Outer x=new Outer(); x.outerMethod(); } } local variable x is accessed from within inner class; needs to be declared final
  • 7. youtube:Zooming | https://github.com/Soba-Arjun/ Method Local Inner Class • Method Local inner classes can’t use local variable of outer method until that local variable is not declared as final. class Outer { void outerMethod() { final int x = 98; System.out.println("inside outerMethod"); class Inner { void innerMethod() { System.out.println("x= "+x); } } Inner y = new Inner(); y.innerMethod(); } } class MethodLocalVariableDemo { public static void main(String[] args) { Outer x=new Outer(); x.outerMethod(); } } Inside outerMethod X = 98
  • 8. youtube:Zooming | https://github.com/Soba-Arjun/ Anonymous Inner Class Anonymous inner classes are declared without any name at all. Super class Sub class class Demo { void show() { System.out.println(“super class"); } } class Flavor1Demo { // An anonymous class with Demo as base class static Demo d = new Demo() { void show() { super.show(); System.out.println(“sub class"); } }; public static void main(String[] args){ d.show(); } }