Java-like and objects

Source: Internet
Author: User

Members of the class:

member variables and member functions.

member functions: Constructors and normal functions.

constructor function:

Function: Initialize an object automatically

Features: 1. Method names and class names are consistent

2. No return value

Ask:

1. Can we define several constructors?

We can define multiple constructors as long as we overload them. If we don't get overloaded, our system will automatically give us a constructor without parameters.

class customer{private  string A; Private int b;          =  ab;} Customer (String ab,int== BC;}}

2. With the same object, how many times can our constructors be dropped?

The same object, we can only invoke it once, and call it once when we are new.

Is there a destructor in 3.Java?

There is no special destructor in Java, and when an object is not referenced to it for a long time and is not used, the garbage collection mechanism automatically dies.

4.this references
This is followed by a member name, which is the equivalent of a special declaration that the member is a member of a class, not a local variable
Inference: A member of any class, when used in a class, can add this. To modify, as long as there is no ambiguity, can also be omitted.

————————————————————————————————————————————————

Java-like and objects

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.