Inner Classes
Internal classes are class inside Class. Internal class case has exceptional association with Outer class. This extraordinary relationship gives internal class access to individual from external class as though they are the piece of external class.
Note: Inner class case has admittance to all individual from the external class(Public, Private and Protected)
Sentence structure for making Inner Class
/external class
class OuterClass {
/inward class
class InnerClass {
}
}
Kind of Inner class
Static
Technique Local
Unknown
Other then over these ordinary internal class
Ordinary Inner Class
Inward classes which are not strategy neighborhood , static or unknown are ordinary internal class.
/external class
class OuterClass {
/inward class
class InnerClass {
}
}
On the off chance that you arrange above code it will create two class document.
outer.class
inner$outer.class
Note: You can't straightforwardly execute the inward's .class document with java summon.
As it is not static inward class so we can't utilize static watchword with it.
Step by step instructions to get to Inner Class
Inward class can be gotten to just through live example of external class.
Inside Outer Class
External class can make example of the inward class similarly as typical class part.
class OuterClass {
private int i = 9;
/Creating case of internal class and calling inward class capacity
open void createInner() {
InnerClass i1 = new InnerClass();
i1.getValue();
}
/inward class declarataion
class InnerClass {
open void getValue() {
/getting to private variable from external class
System.out.println("value of i - " + i);
}
}
}
From Outside Outer Class
Make external class case and afterward inward class occasion.
class MainClass {
open static void main(String[] args) {
/Creating external class case
Outerclass = new OuterClass();
/Creating inward class occasion
OuterClass.InnerClass innerclass = outerclass.new InnerClass();
/Classing inward class strategy
innerclass.getValue();
}
}
Above code can likewise be supplanted with
1
OuterClass.InnerClass innerClass = new OuterClass.new InnerClass();
this catchphrase
There are some standards connected with this and it allude the right now executing Object. So if there should arise an occurrence of Inner class "this" catchphrase will allude the as of now executing inward class Object. However, to get this for external class use "OuterClass.this".
Modifiers Applied
Ordinary internal class will be dealt with like individual from the external class so it can have a few Modifiers instead of Class.
last
dynamic
open
private
ensured
strictfp
Note: Don't get mistook for the modifiers of Class and Inner Class. They are totally diverse.
Strategy Local Inner Class
At the point when an internal class is characterized inside the technique for Outer Class it gets to be Method neighborhood inward class.
Sentence structure for Creating Method Local Inner Class
class OuterClass {
private int i = 9;
/Creating occasion of internal class and calling inward class capacity
open void innerMethod() {
/internal class declarataion inside strategy
class InnerClass {
open void getValue() {
/getting to private variable from external class
System.out.println("value of i - " + i);
}
}
/internal class occurrence creation
InnerClass i1 = new InnerClass();
i1.getValue();
}
}
Presently meaning of internal class is inside a strategy in Outer class. Still the occurrence of the external class can be made yet simply after meaning of inward class as should be obvious above.
Note:
Strategy nearby internal class can be instantiated inside the technique where it is characterized and no where else.
Strategy nearby internal class can not utilize the variable characterized in technique where it id characterized still it can utilize the example variable.
On the off chance that technique nearby variable is "Last" strategy neighborhood internal class can utilize it.(* Now variable is Final)
Modifiers Applied to Method Local Inner Class
Technique neighborhood internal classes are qualified for modifiers like nearby variable so a strategy nearby inward class can have last or unique.
Cheatsheet
Inward class is individual from encasing class.
External class reference is required to start inward class.
Inward class are of 4 sort.
Inward classes characterized inside technique are strategy nearby internal class.
Technique neighborhood internal class can not get to strategy nearby variable.
Last and Abstract are the main modifiers accessible to technique neighborhood internal class.
Ananymous inward class don't have any name.
Internal classes having Static modifier are known as Static inward class.
Static settled class can not get to non static individual from external class.














