构造方法
2018-05-21 16:06 yelena 阅读(142) 评论(0) 编辑 收藏 举报格式: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+"\t工号:"+num+"\t工资:"+salary); } }
构造方法在创建对象的时候使用1次,普通方法能多次调用