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:
OuterClassReference.new MemberInnerClassConstructor();
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
Python Course full playlist: • Python Tutorial in Tamil
C Language Course full playlist: • C Language Full Course
Python Course English full playlist: • Python Tutorial in English
Java Course English full playlist: • Java Tutorial in English
Subscribe to our channel by clicking here 👉👉🏾 / @arivuinfo_6666
#ARIVU_INFO
In questa pagina del sito puoi guardare il video online Java Tutorial | Part 49 | Member Inner Class with Program della durata di ore minuti seconda in buona qualità , che l'utente ha caricato ARIVU INFO 26 dicembre 2023, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 20 volte e gli è piaciuto 2 spettatori. Buona visione!