Java-Preliminary Understanding-tenth-inner class-Details

Source: Internet
Author: User

One.

Start by writing a special point program to learn about the inner class knowledge points.

(In the absence of explanation, first comb yourself, outer this external class function to access the inner class, you must also create an inner class object)

The result of compiling the run, I guess is 5. The DOS results show that we guessed there was nothing wrong.

If we want to output the NUM is 4, how to modify it. My idea is to change the method body to new Outer (). Num. But the method used in the video is different from mine, and the show method in the called Inner class has been modified to become the output this.num, which is num in the object, not num in the method body.

Next is the printing num=3 case, the output statement to Outer.this.num, in fact, before the output num=4, but also can be written Inner.this.num, but inner more redundant, do not write.

Here is a question about the number of points (.) In the knowledge point of the class and object. What are the rules of the Operation ? Is there a clear statement?

There is no such thing as a series of NUM when actually developing.

Why does an inner class have direct access to members in an external class? The representation is that NUM is placed in the inner class, but it is called num in the outer class. Just like method (), where the method body is written with show (), why write the Show () method from the method () and have direct access to other members? That's because this is omitted here, which is actually this.num.

The call is for a reason, not for granted.

This is the object of the outer class.

Java-Preliminary Understanding-tenth-inner class-Details

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.