Core java tutorial for beginners
A tutorial blog which explains different core concepts related to Java along with programming examples

April 30, 2015 Categories: Core Java Basics. No Comments on Nested Class

In this article we will look at what is a nested class and how to define a nested class and access the nested class members in a Java program.

 

Java 1.1 added support for nested classes. A class defined as a member of another class definition is known as a nested class. A nested class can be either static or non-static. The non-static nested class is known as an inner class.

 

The enclosing class of an inner class can be called as an outer class. An inner class can access all the members of an outer class. But the outer class cannot access the inner class members. Inner classes and anonymous classes (inner classes without a name) are useful in event handling.

 

Below Java program demonstrates inner class (non-static nested class):

 

 

In the above example Details is the inner class and Person is the outer class.

Note: Do you have a question on this article or have a suggestion to make this article better? You can ask or suggest us by filling in the below form. After commenting, your comment will be held for moderation and will be published in 24-48 hrs.

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll Up
Thank you for visiting startertutorials.com! If you like this website do share with your friends by clicking on the social icons available on the left hand side.

As the domain name is quite large to remember, use this short domain to visit this site. Short domain: stuts.me