Java Inner Classes | |||
![]() ![]() ![]() | |||
In Java, it is also possible to nest classes (a class within a class). The purpose of nested classes is to group classes that belong together, which makes your code more readable and maintainable. To access the inner class, create an object of the outer class, and then create an object of the inner class:
Private Inner Class Unlike a "regular" class, an inner class can be
If you try to access a private inner class from an outside class, an error occurs:
Static Inner Class An inner class can also be
Access Outer Class From Inner Class One advantage of inner classes, is that they can access attributes and methods of the outer class:
Tags: Access Outer Class From Inner Class Java Java Inner Classes Private Inner Class Static Inner Class ![]() ![]() | |||
| |||
| |||
|
SIMILAR POSTSJava PolymorphismJava Inheritance (Subclass and Superclass)Java PackagesJava Classes and ObjectsJava RecursionJava ScopeJava MethodsJava While Loop/Do While Loop/For Loop/For-Each Loop/Break/ContinueJava Switch StatementsJava Short Hand If...Else (Ternary Operator)Java If ... ElseJava MathJava VariablesJava CommentsThe Print() MethodJava SyntaxJava Getting StartedWhat is Java?Machine Learning Types and Programming LanguagesJava Tutorials associated with AP Computer Science ACreating a simple Java Servlet (Web Server Page) with Apache Maven on Microsoft WindowsJava Servlet ExampleDifference between Java and Javascript |