黑马程序员技术交流社区
标题:
标准类的定义格式
[打印本页]
作者:
15863453752
时间:
2015-8-29 22:10
标题:
标准类的定义格式
class DemoEmployee {
public static void main(String[] args) {
Employee e1 =new Employee();
e1.setName("张三");
e1.setId(100100);
e1.setSalary(18000);
System.out.println("姓名:"+e1.getName()+",卡号:"+e1.getId()+",薪水:"+e1.getSalary());
Employee e2 = new Employee("李四",100220,19000);
e2.work();
}
}
class Employee {
private String name;
private int id;
private int salary;
public Employee() {
}
public Employee(String name,int id,int salary) {
this.name = name;
this.id = id;
this.salary = salary;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setId(int id) {
this.id = id;
}
public int getId() {
return id;
}
public void setSalary(int salary) {
this.salary = salary;
}
public int getSalary() {
return salary;
}
public void work() {
System.out.println(name + "..."+id+"..."+salary);
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2