Java Learning Note 2

Source: Internet
Author: User

Anonymous objects

Packaging

constructor function

This

1, Anonymous object: Do not create object names, directly use the object, after the use of the anonymous object will disappear

New Student (). Start ();

2, Encapsulation: Hide some detailed details, using some public methods, is the use of external classes

private int A;

private void A ();

3. Constructor function

To create a method with the same public as the class name in a class

public Student (); This construction method is created automatically when the object is created, and if you create a constructor manually, the default method of the system disappears.

Public Student (int a);

4, this

Represents the method or property of the class itself.

You can also use this in the constructor method, but you will get an error if you use the method before other statements.

Note: The use of this in the constructor method cannot be called by a colleague two dog miscellaneous methods, as the following example is wrong.

Public Student (String name) {

This (a, b);

}

Public Stuent (String Name,int age) {

This (name);

}

Java Learning Note 2

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.