filmov
tv
Java Tutorial | Part 49 | Member Inner Class with Program

Показать описание
Java inner class or nested class is a class that is declared inside the class.
Syntax of Inner class
class Java_Outer_class
{
//code
class Java_Inner_class
{
//code
}
}
Advantage of Java inner classes
Nested classes represent a particular type of relationship that is it can access all the members (data members and methods) of the outer class, including private.
Nested classes are used to develop more readable and maintainable code because it logically group classes and interfaces in one place only.
Code Optimization: It requires less code to write.
Types of Nested classes
There are two types of nested classes non-static and static nested classes. The non-static nested classes are also known as inner classes.
1 Non-static nested class (inner class)
Member inner class
Anonymous inner class
Local inner class
2 Static nested class
Member inner class
A non-static class that is created inside a class but outside a method is called member inner class. It is also known as a regular inner class. It can be declared with access modifiers like public, private, and protected.
How to instantiate Member Inner class in Java
An object or instance of a member's inner class always exists within an object of its outer class. The new operator is used to create the object of member inner class with slightly different syntax.
The general form of syntax to create an object of the member inner class is as follows:
Syntax:
Here, OuterClassReference is the reference of the outer class followed by a dot which is followed by the new operator.
If this video is useful to you, please like and share If you didn't subscribe kindly subscribe. So that you will get a notification about my new videos
#ARIVU_INFO
Syntax of Inner class
class Java_Outer_class
{
//code
class Java_Inner_class
{
//code
}
}
Advantage of Java inner classes
Nested classes represent a particular type of relationship that is it can access all the members (data members and methods) of the outer class, including private.
Nested classes are used to develop more readable and maintainable code because it logically group classes and interfaces in one place only.
Code Optimization: It requires less code to write.
Types of Nested classes
There are two types of nested classes non-static and static nested classes. The non-static nested classes are also known as inner classes.
1 Non-static nested class (inner class)
Member inner class
Anonymous inner class
Local inner class
2 Static nested class
Member inner class
A non-static class that is created inside a class but outside a method is called member inner class. It is also known as a regular inner class. It can be declared with access modifiers like public, private, and protected.
How to instantiate Member Inner class in Java
An object or instance of a member's inner class always exists within an object of its outer class. The new operator is used to create the object of member inner class with slightly different syntax.
The general form of syntax to create an object of the member inner class is as follows:
Syntax:
Here, OuterClassReference is the reference of the outer class followed by a dot which is followed by the new operator.
If this video is useful to you, please like and share If you didn't subscribe kindly subscribe. So that you will get a notification about my new videos
#ARIVU_INFO