Features of internal classes in java

Source: Internet
Author: User

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.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.