Constructor (the constructor | Method)

First, the characteristics

1. must be consistent with the class name

2. There is no return type | void

3. and used with the new, new + constructor creates a new object

4. Define the function is used to initialize a class object in Java

5. If the category is not added to any of the constructor will be automatically added to the empty configuration (no argument constructor) after javac compiler, has been added to the constructor, the compiler will not automatically added javac

6. The builder may be present in return, return out selectively constructor

7. modifier can not be a final abstract static 

Second, the constructor overloads

 1 public class User{
 2     String name;
 3     String password;
 4 
 5     public User(){
 6     }//默认构造器
 7 
 8     public User(String name,String password){
 9         super();       
10         this.name=name;
11         this.password=password;
12     }
13 
14     public static void main(String[] args){
15         User user = new User("小七","123567");
16     }
17 }

 

Guess you like

Origin www.cnblogs.com/jaci/p/11361552.html