1.可以创建对象
2. 可以访问成员方法
注意:
3. 不可以用private修饰构造器
4. 构造器和类的方法名一样
5. 多个构造器可以重载
6. 没有返回值
7. 构造方法不可以继承
package com.demo;
public class Constructor {
private int id;
private String username;
public Constructor(){
System.out.println( "我是无参构造器" );
}
public Constructor(int id){
this.id=id;
System.out.println( 14 );
}
public Constructor(int id,String username){
this.id=id;
this.username=username;
System.out.println( "我是两个参数的构造器" );
}
public static void main(String[] args) {
Constructor constructor=new Constructor( );
Constructor constructor1=new Constructor( 1 );
Constructor constructor2=new Constructor( 1,"houzhi,hold on it,just do it again and again" );
}
}