黑马程序员技术交流社区
标题:
抽象类学习,明天面向对象最后一天
[打印本页]
作者:
石头stone
时间:
2016-5-22 17:46
标题:
抽象类学习,明天面向对象最后一天
class Test1_Emplyee {
public static void main(String[] args) {
Employee e = new Coder("张三","零零发",10000);
e.work();
}
}
abstract class Employee {
private String name;
private String id;
private double salary;
public Employee() {}
public Employee(String name,String id,double 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(String id) {
this.id = id;
}
public String getId() {
return id;
}
public void setSalary(double salary) {
this.salary = salary;
}
public double getSalary() {
return salary;
}
public abstract void work();
}
class Coder extends Employee {
public Coder() {}
public Coder(String name,String id,double salary) {
super(name,id,salary);
}
public void work() {
System.out.println("我的姓名是:" + getName() +",工号是" + getId() +",工资是" + getSalary()+",我的工作内容是敲代码.");
}
}
复制代码
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2