Course Content

Course Content


Nested Classes in Java

In this video of our ongoing Core Java course, we will see that what are Nested class in Java programming language.

A class within another class is known as Nested class in Java. The scope of the nested class is bounded by the scope of its enclosing class.

There are two different types of Nested classes,
1. Non-static Nested class in Java (Inner class)
2. Static Nested class in Java

Non-static Nested class in Java is further divided into three parts,
1. Member,
2. Anonymous, &
3. Local inner classes

When we make another class within a class, it is known as Member Inner class in Java. When we do not provide any name to our class, it is known as Anonymous Inner class in Java. And when we define a class within any method it is known as Local Inner class in Java.

Syntax of Inner class in Java is -
class Java_Outer_class
class Java_Inner_class
} }

Advantage of Inner class in Java are as follows :
1. Nested classes represent a special type of relationship that is it can access all the members (data members and methods) of outer class including private.
2. Nested classes are used to develop more readable and maintainable code because it logically group classes and interfaces in one place only. And also it requires less code to write.
3. A static class ie. class created inside a class is called Static nested class in Java. It cannot access non-static data members and methods. It can be accessed by outer class name.

Thus, this is what Nested class in Java is, and we have also seen it’s two different types. In the upcoming further video we will see that what are Keywords in Java programming language with an example.


Recommended Courses

Share With Friend

Have a friend to whom you would want to share this course?

Download The Apps

Code Scan or Download the app
Google Play Store
297K+ Downloads
4.5 Rating
10K+ Reviews
  • Learn anywhere on the go
  • Get regular updates about your enrolled or new courses
  • Share content with your friends
  • Evaluate your progress through practice tests
  • No internet connection needed
  • Enroll for the webinar and join at the time of the webinar from anywhere