The construction method of Java basic note for Jen Baby

Source: Internet
Author: User

Construction method
Grammar:
public class name () {
}
1. When instantiating an object, call the default hidden parameterless constructor of the class.
2. If there is a custom constructor method, the default class's parameterless constructor is not called.
Class Name Object name =new class name ();//This is the parameterless construction method of the called Class
Class Name Object name =new class name (name,age);//This is a method to call a class with a parameter constructor
3. The method name is the same as the class name. Case sensitive
4. The construction method is not void and is considered a normal method if there is void
5. The function of the construction method is generally used to initialize the object properties
6. If you want to invoke another constructor within the constructor method use this (parameter); This must be placed in the first sentence

Method overloading
In the same class, the method names in the same parameter list (number type Order) are different from the access modifier return value.
The invocation is based on the argument list to determine the method of the specific invocation.
Multiple construction methods take advantage of the overloaded method

Scope of the variable
1. member variables and local variables
Variables that are defined in a class are called member variables.
Variables defined in a method are called local variables.
Member variables: Methods of other classes to access him, you must create an object of that class before you can pass the "." To reference.
Local variables: His scope is only within the method of the variable, so it can only be used in this method.
Note the point:
Scopes are different.
The initial values are different.
Local variables with the same name are not allowed in the same method. In different methods, you can have local variables of the same name.
Local variables can have the same name as member variables, and when used, local variables have higher precedence.

The construction method of Java basic note for Jen Baby

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.