SlideShare ist ein Scribd-Unternehmen logo
1 von 7
Java Session 8
Inner Classes
• Inner classes let you define one class within another. They provide a type of scoping for your classes
since you can make one class a member of another class. Just as classes have member variables and
methods, a class can also have member classes.
• Different kinds of inner classes : Inner classes, Method-local inner classes, Anonymous inner classes,
Static nested classes.
• Regular Inner Classes :
• You're an OO programmer, so you know that for reuse and flexibility/extensibility you need to keep your classes
specialized. In other words, a class should have code only for the things an object of that particular type needs to do;
any other behavior should be part of another class better suited for that job. Sometimes, though, you find yourself
designing a class where you discover you need behavior that belongs in a separate, specialized class, but also needs to
be intimately tied to the class you're designing.
• One of the key benefits of an inner class is the "special relationship" an inner class instance shares with an instance of
the outer class. That "special relationship" gives code in the inner class access to members of the enclosing (outer)
class, as if the inner class were part of the outer class. In fact, that's exactly what it means: the inner class is a part of
the outer class. Not just a "part" but a full-fledged, card-carrying member of the outer class. Yes, an inner class
instance has access to all members of the outer class, even those marked private.
• Regular inner class can't have static declarations of any kind. The only way you can access the inner class is through a
live instance of the outer class!
• Instantiating an Inner Class : To create an instance of an inner class, you must have an instance of the outer class to
tie to the inner class. There are no exceptions to this rule: an inner class instance can never stand alone without a direct
relationship to an instance of the outer class
Regular Inner classes
• Referencing the Inner or Outer Instance from Within the Inner Class : How does an object refer
to itself normally? By using the this reference.
• The keyword this can be used only from within instance code. In other words, not within static code.
• The this reference is a reference to the currently executing object. In other words, the object whose reference was
used to invoke the currently running method.
• The this reference is the way an object can pass a reference to itself to some other code, as a method argument:
mc.doStuff(this);
• Within an inner class code, the this reference refers to the instance of the inner class, as you'd probably expect,
since this always refers to the currently executing object. But what if the inner class code wants an explicit
reference to the outer class instance that the inner instance is tied to? In other words, how do you reference the
"outer this"? Although normally the inner class code doesn't need a reference to the outer class, since it already has
an implicit one it's using to access the members of the outer class, it would need a reference to the outer class if it
needed to pass that reference to some other code as follows : MyOuter.this
• To reference the inner class instance itself, from within the inner class code, use this.
• To reference the "outer this" (the outer class instance) from within the inner class code, use
NameOfOuterClass.this (example, MyOuter.this).
• A regular inner class is a member of the outer class just as instance variables and methods are, so the
following modifiers can be applied to an inner class:
•final, abstract, public, private, protected,
• static—but static turns it into a static nested class not an inner class
•Strictfp
• Ex : https://gist.github.com/rajeevprasanna/10519350
Method-Local Inner classes
• A regular inner class is scoped inside another class's curly braces, but outside any method code (in other
words, at the same level that an instance variable is declared). But you can also define an inner class
within a method.
• A method-local inner class can be instantiated only within the method where the inner class is defined. In
other words, no other code running in any other method—inside or outside the outer class—can ever
instantiate the method-local inner class. Like regular inner class objects, the method-local inner class
object shares a special relationship with the enclosing (outer) class object, and can access its private (or
any other) members
• The inner class object cannot use the local variables of the method the inner class is in. Why not?
• The local variables of the method live on the stack, and exist only for the lifetime of the method. You
already know that the scope of a local variable is limited to the method the variable is declared in. When
the method ends, the stack frame is blown away and the variable is history. But even after the method
completes, the inner class object created within it might still be alive on the heap if, for example, a
reference to it was passed into some other code and then stored in an instance variable. Because the local
variables aren't guaranteed to be alive as long as the method-local inner class object, the inner class
object can't use them. Unless the local variables are marked final!
• The only modifiers you can apply to a method-local inner class are abstract and final, but as always,
never both at the same time.
• Local class declared in a static method has access to only static members of the enclosing class, since
there is no associated instance of the enclosing class. If you're in a static method there is no this, so an
inner class in a static method is subject to the same restrictions as the static method. In other words, no
access to instance variables.
• Ex : https://gist.github.com/rajeevprasanna/10519905
Anonymous Inner Classes
• An anonymous class is an inner class that does not have a name at all. And whose instance is being
created at the time of its creation.
• Creating anonymous class is quicker and simple. Anonymous inner classes are useful when we need to
inherit a few properties (only one method) of a superclass and this is not a good idea to take overhead of
creating a separate subclass for doing things so simple.
• In java anonymous classes can be created in either of the two ways. 1) Using a class reference variable.
2) Using an interface.
• Anonymous classes are just like local classes, besides they don’t have a name. In Java anonymous
classes enables the developer to declare and instantiate a class at the same time.
• Like other inner classes, an anonymous class has access to the members of its enclosing class.
• One more thing to keep in mind about anonymous interface implementers—they can implement only one
interface. There simply isn't any mechanism to say that your anonymous inner class is going to
implement multiple interfaces. In fact, an anonymous inner class can't even extend a class and implement
an interface at the same time.
• The inner class has to choose either to be a subclass of a named class— and not directly implement any
interfaces at all—or to implement a single interface. By directly, we mean actually using the keyword
implements as part of the class declaration.
• If the anonymous inner class is a subclass of a class type, it automatically becomes an implementer of
any interfaces implemented by the superclass.
• Ex : https://gist.github.com/rajeevprasanna/10520664
Static Nested Classes
• You'll sometimes hear static nested classes referred to as static inner classes, but they really aren't inner classes at all, by
the standard definition of an inner class.
• While an inner class (regardless of the flavor) enjoys that special relationship with the outer class (or rather the instances
of the two classes share a relationship), a static nested class does not. It is simply a non-inner (also called "top-level")
class scoped within another. So with static classes it's really more about name-space resolution than about an implicit
relationship between the two classes.
• The class itself isn't really "static"; there's no such thing as a static class. The static modifier in this case says that the
nested class is a static member of the outer class. That means it can be accessed, as with other static members, without
having an instance of the outer class.
• Just as a static method does not have access to the instance variables and nonstatic methods of the class, a
static nested class does not have access to the instance variables and nonstatic methods of the outer class.
Look for static nested classes with code that behaves like a nonstatic (regular inner) class.
• Ex: https://gist.github.com/rajeevprasanna/10520895
• Git repo URL of all examples : https://github.com/rajeevprasanna/JavaSession8
Javasession8

Weitere ähnliche Inhalte

Was ist angesagt?

Complete java&j2ee
Complete java&j2eeComplete java&j2ee
Complete java&j2ee
Shiva Cse
 
Inner classes9 cm604.28
Inner classes9 cm604.28Inner classes9 cm604.28
Inner classes9 cm604.28
myrajendra
 
GeekAustin PHP Class - Session 7
GeekAustin PHP Class - Session 7GeekAustin PHP Class - Session 7
GeekAustin PHP Class - Session 7
jimbojsb
 

Was ist angesagt? (20)

Lecture 1 - Objects and classes
Lecture 1 - Objects and classesLecture 1 - Objects and classes
Lecture 1 - Objects and classes
 
15reflection in c#
15reflection  in c#15reflection  in c#
15reflection in c#
 
Complete java&j2ee
Complete java&j2eeComplete java&j2ee
Complete java&j2ee
 
Packages
PackagesPackages
Packages
 
Inner classes9 cm604.28
Inner classes9 cm604.28Inner classes9 cm604.28
Inner classes9 cm604.28
 
Introducing classes
Introducing classesIntroducing classes
Introducing classes
 
Unit 4
Unit 4Unit 4
Unit 4
 
Java Inner Classes
Java Inner ClassesJava Inner Classes
Java Inner Classes
 
Pj01 x-classes and objects
Pj01 x-classes and objectsPj01 x-classes and objects
Pj01 x-classes and objects
 
Class
ClassClass
Class
 
Abstract classes & interfaces
Abstract classes & interfacesAbstract classes & interfaces
Abstract classes & interfaces
 
Pi j3.1 inheritance
Pi j3.1 inheritancePi j3.1 inheritance
Pi j3.1 inheritance
 
GeekAustin PHP Class - Session 7
GeekAustin PHP Class - Session 7GeekAustin PHP Class - Session 7
GeekAustin PHP Class - Session 7
 
Java Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overridingJava Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overriding
 
Introduction to value types
Introduction to value typesIntroduction to value types
Introduction to value types
 
OWL 2 Overview
OWL 2 OverviewOWL 2 Overview
OWL 2 Overview
 
Java introduction
Java introductionJava introduction
Java introduction
 
JAVA PROGRAMMING – Packages - Stream based I/O
JAVA PROGRAMMING – Packages - Stream based I/O JAVA PROGRAMMING – Packages - Stream based I/O
JAVA PROGRAMMING – Packages - Stream based I/O
 
Java Core
Java CoreJava Core
Java Core
 
The Ruby Object Model by Rafael Magana
The Ruby Object Model by Rafael MaganaThe Ruby Object Model by Rafael Magana
The Ruby Object Model by Rafael Magana
 

Ähnlich wie Javasession8

[圣思园][Java SE]Inner class
[圣思园][Java SE]Inner class[圣思园][Java SE]Inner class
[圣思园][Java SE]Inner class
ArBing Xie
 
Classes in Java great learning.pdf
Classes in Java great learning.pdfClasses in Java great learning.pdf
Classes in Java great learning.pdf
SHASHIKANT346021
 

Ähnlich wie Javasession8 (20)

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
 
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
 
OCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference CardOCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference Card
 
Lecture09.ppt
Lecture09.pptLecture09.ppt
Lecture09.ppt
 
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
 
Inner class
Inner classInner class
Inner class
 
Nested class in java
Nested class in javaNested class in java
Nested class in java
 
Java/J2EE interview Qestions
Java/J2EE interview QestionsJava/J2EE interview Qestions
Java/J2EE interview Qestions
 
5. OBJECT ORIENTED PROGRAMMING USING JAVA - INHERITANCE.ppt
5. OBJECT ORIENTED PROGRAMMING USING JAVA - INHERITANCE.ppt5. OBJECT ORIENTED PROGRAMMING USING JAVA - INHERITANCE.ppt
5. OBJECT ORIENTED PROGRAMMING USING JAVA - INHERITANCE.ppt
 
Nested classes in java
Nested classes in javaNested classes in java
Nested classes in java
 
Abstraction in java.pptx
Abstraction in java.pptxAbstraction in java.pptx
Abstraction in java.pptx
 
[圣思园][Java SE]Inner class
[圣思园][Java SE]Inner class[圣思园][Java SE]Inner class
[圣思园][Java SE]Inner class
 
Inner class
Inner classInner class
Inner class
 
Classes in Java great learning.pdf
Classes in Java great learning.pdfClasses in Java great learning.pdf
Classes in Java great learning.pdf
 
[OOP - Lec 06] Classes and Objects
[OOP - Lec 06] Classes and Objects[OOP - Lec 06] Classes and Objects
[OOP - Lec 06] Classes and Objects
 
Class Members Access/Visibility Guide (Checklist)
Class Members Access/Visibility Guide (Checklist)Class Members Access/Visibility Guide (Checklist)
Class Members Access/Visibility Guide (Checklist)
 
Object Oriented Programming Tutorial.pptx
Object Oriented Programming Tutorial.pptxObject Oriented Programming Tutorial.pptx
Object Oriented Programming Tutorial.pptx
 
Nested class
Nested classNested class
Nested class
 
PPT Lecture-1.4.pptx
PPT Lecture-1.4.pptxPPT Lecture-1.4.pptx
PPT Lecture-1.4.pptx
 

Mehr von Rajeev Kumar (9)

Db performance optimization with indexing
Db performance optimization with indexingDb performance optimization with indexing
Db performance optimization with indexing
 
Javasession10
Javasession10Javasession10
Javasession10
 
Jms intro
Jms introJms intro
Jms intro
 
Javasession6
Javasession6Javasession6
Javasession6
 
Javasession7
Javasession7Javasession7
Javasession7
 
Javasession5
Javasession5Javasession5
Javasession5
 
Javasession4
Javasession4Javasession4
Javasession4
 
Java session 3
Java session 3Java session 3
Java session 3
 
Java session2
Java session2Java session2
Java session2
 

Kürzlich hochgeladen

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Kürzlich hochgeladen (20)

Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 

Javasession8

  • 2. Inner Classes • Inner classes let you define one class within another. They provide a type of scoping for your classes since you can make one class a member of another class. Just as classes have member variables and methods, a class can also have member classes. • Different kinds of inner classes : Inner classes, Method-local inner classes, Anonymous inner classes, Static nested classes. • Regular Inner Classes : • You're an OO programmer, so you know that for reuse and flexibility/extensibility you need to keep your classes specialized. In other words, a class should have code only for the things an object of that particular type needs to do; any other behavior should be part of another class better suited for that job. Sometimes, though, you find yourself designing a class where you discover you need behavior that belongs in a separate, specialized class, but also needs to be intimately tied to the class you're designing. • One of the key benefits of an inner class is the "special relationship" an inner class instance shares with an instance of the outer class. That "special relationship" gives code in the inner class access to members of the enclosing (outer) class, as if the inner class were part of the outer class. In fact, that's exactly what it means: the inner class is a part of the outer class. Not just a "part" but a full-fledged, card-carrying member of the outer class. Yes, an inner class instance has access to all members of the outer class, even those marked private. • Regular inner class can't have static declarations of any kind. The only way you can access the inner class is through a live instance of the outer class! • Instantiating an Inner Class : To create an instance of an inner class, you must have an instance of the outer class to tie to the inner class. There are no exceptions to this rule: an inner class instance can never stand alone without a direct relationship to an instance of the outer class
  • 3. Regular Inner classes • Referencing the Inner or Outer Instance from Within the Inner Class : How does an object refer to itself normally? By using the this reference. • The keyword this can be used only from within instance code. In other words, not within static code. • The this reference is a reference to the currently executing object. In other words, the object whose reference was used to invoke the currently running method. • The this reference is the way an object can pass a reference to itself to some other code, as a method argument: mc.doStuff(this); • Within an inner class code, the this reference refers to the instance of the inner class, as you'd probably expect, since this always refers to the currently executing object. But what if the inner class code wants an explicit reference to the outer class instance that the inner instance is tied to? In other words, how do you reference the "outer this"? Although normally the inner class code doesn't need a reference to the outer class, since it already has an implicit one it's using to access the members of the outer class, it would need a reference to the outer class if it needed to pass that reference to some other code as follows : MyOuter.this • To reference the inner class instance itself, from within the inner class code, use this. • To reference the "outer this" (the outer class instance) from within the inner class code, use NameOfOuterClass.this (example, MyOuter.this). • A regular inner class is a member of the outer class just as instance variables and methods are, so the following modifiers can be applied to an inner class: •final, abstract, public, private, protected, • static—but static turns it into a static nested class not an inner class •Strictfp • Ex : https://gist.github.com/rajeevprasanna/10519350
  • 4. Method-Local Inner classes • A regular inner class is scoped inside another class's curly braces, but outside any method code (in other words, at the same level that an instance variable is declared). But you can also define an inner class within a method. • A method-local inner class can be instantiated only within the method where the inner class is defined. In other words, no other code running in any other method—inside or outside the outer class—can ever instantiate the method-local inner class. Like regular inner class objects, the method-local inner class object shares a special relationship with the enclosing (outer) class object, and can access its private (or any other) members • The inner class object cannot use the local variables of the method the inner class is in. Why not? • The local variables of the method live on the stack, and exist only for the lifetime of the method. You already know that the scope of a local variable is limited to the method the variable is declared in. When the method ends, the stack frame is blown away and the variable is history. But even after the method completes, the inner class object created within it might still be alive on the heap if, for example, a reference to it was passed into some other code and then stored in an instance variable. Because the local variables aren't guaranteed to be alive as long as the method-local inner class object, the inner class object can't use them. Unless the local variables are marked final! • The only modifiers you can apply to a method-local inner class are abstract and final, but as always, never both at the same time. • Local class declared in a static method has access to only static members of the enclosing class, since there is no associated instance of the enclosing class. If you're in a static method there is no this, so an inner class in a static method is subject to the same restrictions as the static method. In other words, no access to instance variables. • Ex : https://gist.github.com/rajeevprasanna/10519905
  • 5. Anonymous Inner Classes • An anonymous class is an inner class that does not have a name at all. And whose instance is being created at the time of its creation. • Creating anonymous class is quicker and simple. Anonymous inner classes are useful when we need to inherit a few properties (only one method) of a superclass and this is not a good idea to take overhead of creating a separate subclass for doing things so simple. • In java anonymous classes can be created in either of the two ways. 1) Using a class reference variable. 2) Using an interface. • Anonymous classes are just like local classes, besides they don’t have a name. In Java anonymous classes enables the developer to declare and instantiate a class at the same time. • Like other inner classes, an anonymous class has access to the members of its enclosing class. • One more thing to keep in mind about anonymous interface implementers—they can implement only one interface. There simply isn't any mechanism to say that your anonymous inner class is going to implement multiple interfaces. In fact, an anonymous inner class can't even extend a class and implement an interface at the same time. • The inner class has to choose either to be a subclass of a named class— and not directly implement any interfaces at all—or to implement a single interface. By directly, we mean actually using the keyword implements as part of the class declaration. • If the anonymous inner class is a subclass of a class type, it automatically becomes an implementer of any interfaces implemented by the superclass. • Ex : https://gist.github.com/rajeevprasanna/10520664
  • 6. Static Nested Classes • You'll sometimes hear static nested classes referred to as static inner classes, but they really aren't inner classes at all, by the standard definition of an inner class. • While an inner class (regardless of the flavor) enjoys that special relationship with the outer class (or rather the instances of the two classes share a relationship), a static nested class does not. It is simply a non-inner (also called "top-level") class scoped within another. So with static classes it's really more about name-space resolution than about an implicit relationship between the two classes. • The class itself isn't really "static"; there's no such thing as a static class. The static modifier in this case says that the nested class is a static member of the outer class. That means it can be accessed, as with other static members, without having an instance of the outer class. • Just as a static method does not have access to the instance variables and nonstatic methods of the class, a static nested class does not have access to the instance variables and nonstatic methods of the outer class. Look for static nested classes with code that behaves like a nonstatic (regular inner) class. • Ex: https://gist.github.com/rajeevprasanna/10520895 • Git repo URL of all examples : https://github.com/rajeevprasanna/JavaSession8