黑马程序员技术交流社区

标题: 刚学的继承 [打印本页]

作者: 吴成    时间: 2016-3-19 22:54
标题: 刚学的继承
class Test_Employee {
        public static void main(String[] args) {
                Manager m = new Manager("张三",35248,8888,9999);
                System.out.println(m.getName() + "----" + m.getNum() +"----" + m.getSalary() +"----" + m.getBonus() );
                m.work();
                Employee e = new Employee();
                e.setName("大明");
                e.setSalary(8000);
                System.out.println(e.getName() + "----" + e.getSalary());
        }
}
class Employee {
        private String name;
        private int  num;
        private int salary;
        public Employee (){}
        public Employee(String name,int num,int salary){
        this.name = name;
        this.num = num;
        this.salary = salary;}
        public void setName(String name){
                this.name = name;}
        public String getName(){
                return name;}
        public void setNum(int num){
                this.num = num;}
        public int getNum(){
                return num;}
        public void setSalary(int salary){
                this.salary = salary;}
        public int getSalary(){
                return salary;}
        public void work(){
                System.out.println("他们都需要工作");}
}
class Programmer extends Employee {
        public Programmer(){  }
        public Programmer(String name,int num, int salary){
                super(name,num,salary);}
        public void work(){
                System.out.println ("程序员是码农");}
}
class Manager extends Employee {
        private int bonus;
        public Manager(){}
        public Manager(String name,int num,int salary,int bonus){
                super(name,num,salary);
                this.bonus = bonus;
        }
       
        public int getBonus(){
                return bonus;}
        public void work(){
                System.out.println("经理可以管别人");}
       
}





欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2