上机练习题——接口

package 接口;

public abstract class Student {
	
	String name;
	int fee;
	Student(String name)
	{
		this.name = name;	
	}
	abstract void setFee(int fee);
	abstract int getFee();
}

package 接口;

public interface Salary {
	int getSalary();
}

package 接口;

public class Graduate extends Student implements Salary {

	int salary;
	Graduate(String name) {
		super(name);
		// TODO Auto-generated constructor stub
		this.name = name;
	}

	@Override
	public int getSalary() {
		// TODO Auto-generated method stub
		return 1500;
	}

	@Override
	void setFee(int fee) {
		// TODO Auto-generated method stub

	}

	@Override
	int getFee() {
		// TODO Auto-generated method stub
		return 0;
	}
	
	boolean isLoan()
	{
		boolean flag=false;
		if(salary<fee)
		{
			//System.out.println("需要贷款");
			flag = true;
		}
		else
		{
			//System.out.println("不需要贷款");
			flag=false;
		}
		return flag;
	}

}

package 接口;

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

	public int getSalary() {
		return 3000;
	}

	
	

}

package 接口;

public class University {
	void payOff(Salary s)
	{
		System.out.println("发放工资"+s.getSalary());
	}
}

package 接口;

public class Test {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Graduate g = new Graduate("小亮");
		g.setFee(100);
		
		University u = new University();
		u.payOff(g);
		System.out.println("是否需要贷款"+g.isLoan());
		
		Teacher t = new Teacher("大王");
		u.payOff(t);
	}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值