学校学生老师工资多态

package stu;


public class Graduate extends Student implements Salary{ 
Graduate(String name) { 
super(name); 

int salary;
void setFee(int fee)
{
    super.fee=fee;
}
int getFee()
{
    return fee;
}
public int getSalary()
{
    salary=1500;
    return salary;
}
boolean isLoan()
{
    if(salary < fee)
        return true;
    return false;
}

}

package stu;
public class Teacher implements Salary{ 
String name ; 
int salary; 
Teacher(String name) 

this.name = name ; 
}


public int getSalary() {
    salary=3000;
    return salary;
}
}

package stu;


public class University { 
void payOff(Salary s) 

System.out.println("当前工资已发放"+s.getSalary()); 

}

package stu;


public class test {


public static void main(String[] args) {
    Graduate g = new Graduate("小亮");
    g.setFee(1300);


    University u =new University();
    u.payOff(g);
    System.out.println("是否需要贷款:"+g.isLoan());
    Teacher t = new Teacher("大王");
    u.payOff(t);
}
}学校学生老师工资多态_第1张图片

你可能感兴趣的:(学校学生老师工资多态)