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.....