Java Internal Class 2 (Member inner Class)

Source: Internet
Author: User

member Inner class:

Feature: The class in which the outer class, the member function, is located.

Difficulty: See comments (related to JVM)

/*when test () is finished, X2 disappears from memory, Inner declaration week, longer than X2, inner is still in the access, giving the feeling as if the life cycle of blood is getting longer solution: let the internal class access the replica of the local variable, that is, this x2 non-x2, two copies of the data disappeared. */ Public classEX10 { Public Static voidMain (string[] args) {Outer out=NewOuter ();    Out.text (); }}classouter{intX1 =1;  Public voidtext () {intx2 = 2; classInner {Final intx3 = 3;//because it's a replica, it's decorated with fianl .             Public voidprint () {System.out.println ("This is the method of the local inner class" + x2);//X2 is the replica above.}} Inner Inner=NewInner ();    Inner.print (); }}

Java Internal Class 2 (Member inner Class)

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.