Nested class in c ++ java

Source: Internet
Author: User

The native framework of android uses a lot of c ++ Nested classes, while the java framework uses a lot of internal Nested classes. I have read some books and code to make a summary.
1. The non-static internal class of java has an external class reference outer. This variable can be used to reference all external variables, including private
2. Static java internal classes are also called Nested classes. static internal classes do not have external references, but they can only call external static methods and variables.
3. Anonymous internal classes are often used to write a listener, which is often used
New listener (){
Xx (){
}
};
4. the internal classes of c ++ are almost equivalent to syntax nesting, while the internal classes of C ++ cannot access the private variables of the external classes, to access the service, you must declare the external class as friend class www.2cto.com in the internal class.
 
From my current understanding, the nested class of c ++ is almost equivalent to a new class, and there may be some small differences;
Java internal classes are not just syntax nesting, but non-static internal classes have semantic relationships with the external, so external references must be established first.
From this point of view, the difference between the two is quite big.

From shcalm's column

Related Article

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.