什么是接口和 抽象类Java

package abscractClass;

class employee {
	public static void main(String[] args) {
		myEmployee pro = new programmer("001", "comi", 18, 25000);
		pro.SiginIn();
		pro.showWork();
		programmer programmer = new programmer("002", "kimi", 21, 0001);
		programmer.SiginIn();
		programmer.showWork();

		myEmployee mannger = new Mannger("001", "COMI", 25, 2500000, 20000);
		mannger.SiginIn();
		mannger.showWork();

		Mannger mannger2 = new Mannger("002", "kimi", 30, 20000, 20000);
		mannger2.SiginIn();
		mannger2.showWork();
	}
}

/** 
 *	抽象类可以包含抽象方法同时也可以拥有方法
 *	而接口是完全抽象的类,,只能包含抽象方法,不能包含其他已经实现的方法
 *	abstract class can own abstract methods mean while can own normal methods
 *	but interface is completely abstract class,
 *	only own abstract methods,can't own other already implements methods.
 *	it just a method head, don't have method body
 * */
interface people{
	public void eat();
	public void sleep();
	public void jump();
}
class comi  implements people{

	@Override
	public void eat() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void sleep() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void jump() {
		// TODO Auto-generated method stub
		
	}
}

abstract class myEmployee {
	
	private String ID;
	private String Name;
	private int Age;
	private double pay;

	public myEmployee(String ID, String Name, int Age, double pay) {
		this.ID = ID;
		this.Name = Name;
		this.Age = Age;
		this.pay = pay;
	}

	public abstract void showWork();

	public void SiginIn() {
		System.out.println(this.Name + " is SingIn ...");
	}
}

class programmer extends myEmployee {
	private String who;

	public programmer(String ID, String Name, int Age, double pay) {
		super(ID, Name, Age, pay);
		this.who = Name;
	}

	@Override
	public void showWork() {
		System.out.println(this.who + " is programming...");
	}

}

class Mannger extends myEmployee {
	private double bonus;
	private String who;

	public Mannger(String ID, String Name, int Age, double pay, double bonus) {
		super(ID, Name, Age, pay);
		this.bonus = bonus;
		this.who = Name;
	}

	@Override
	public void showWork() {
		System.out.println(this.who + " is drinking tea.....");
	}

}

输出

comi is SingIn ...
comi is programming...
kimi is SingIn ...
kimi is programming...
COMI is SingIn ...
COMI is drinking tea.....
kimi is SingIn ...
kimi is drinking tea.....

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值