格式:public 类名(){
};
写了构造方法后,必须有一个空参数的构造方法
构造方法可以重载
package com.oracle.Demo05; public class Employee { private String name; private int num; private double salary; public Employee(){ } public Employee(String name){ this.name = name; } public Employee(String name,int num,double salary){ this(name); this.num = num; this.salary = salary; } public void show(){ System.out.println("姓名:"+name+" 工号:"+num+" 工资:"+salary); } }
构造方法在创建对象的时候使用1次,普通方法能多次调用