Java section 44th refers to an object of an external class

Source: Internet
Author: User

2016-06-30

 Packagecom.java1995;/*** 1. Referencing an object of an external class * Inner:this.count * Outer:Outer.this.count *@authorAdministrator **///External Class Public classOuter {Private intCount =1 ; //Inner class    classinner{Private intCount = 2; //methods for inner classes         Public voidPrintintcount) {            //the count in the inner class methodSystem.out.println (count); //the count of the inner classSystem.out.println ( This. Count); //the count of the external classSystem.out.println (Outer. This. Count); }    }         Public Static voidMain (string[] args) {Outer Outer=NewOuter (); Outer.Inner I=outer.NewInner (); I.print (3); }}

 Packagecom.java1995;/*** 2. Inheritance of internal classes (understand) *@authorAdministrator **/ Public classTestextendsa.b{//before instantiating B, instantiate a     PublicTest (a a) {a.Super(); }}//instantiate an inner class that requires an object of an external classclassa{classb{}}

Resources

[1] Java Easy Start Classic tutorial "full version"

Java section 44th refers to an object of an external class

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.