An internal class is a class defined inside a class, which is equivalent to a nested class in C ++. For example, the following defines an internal class:
Class Parent
{
Private StringBuffer sb1;
Int;
Parent ()
{
Sb1 = new StringBuffer ("Hello java! ");
A = 10;
}
InnerCls pMethod (int r)
{
Return new InnerCls (r );
}
Private class InnerCls
{Int property1;
InnerCls (int B)
{
Property1 = B;
}
Public static int innerMethod ()
{
Sb1.append ("You are so beautiful! ")
Return proterty1 *;
}
}
}
// Define the main class
Public class test
{
Public static void main (String args [])
{
Parent p1 = new Parent ();
InnerCls in1 = p1.pMethod (int a = 2)
In1.innerMethod ();
}
}
Note:
1. An external class object created in the program is an object that does not create an internal class;
2. An internal class object can access any member of its external class.
3. The internal class is invisible to other external entities.