Java oop題和代碼:抽象類人,抽象方法,繼承,接口,在main函數(shù)中進(jìn)行調(diào)用

聲明抽象類人,包含編號(hào),姓名,年齡屬性,包含抽象方法吃飯,學(xué)習(xí),?聲明接口購物,聲明接口上課,聲明接口做備課,聲明接口做作業(yè),聲明老?師類繼承自抽象類人類實(shí)現(xiàn)購物和備課的接口,聲明學(xué)生類繼承抽象類人類?實(shí)現(xiàn)寫作業(yè)和上課的接口,在main函數(shù)中進(jìn)行調(diào)用
package b;
public class demo {
public static void main(String[] args) {
ren t = new teacher();// /向上轉(zhuǎn)型,抽象類
gouwu t1 = new teacher();// 向上轉(zhuǎn)型,接口
beike t2 = new teacher();
t.name = "詩書";
t.chifan();
t1.maidx();
t2.bk();
ren s = new student();
shangke s1 = new student();
zuozuoye s2 = new student();
s.name = "畫唱";
s.xuexi();
s1.sk();
s2.zzy();
}
}
abstract class ren {
String id;
String name;
int age;
public abstract void chifan();
public abstract void xuexi();
// 抽象類不能包含學(xué)習(xí),因?yàn)樗腥瞬灰欢ǘ紝W(xué)習(xí),題目有錯(cuò),這里按題目要求來,課程聲明為接口
}
interface gouwu {
public abstract void maidx();
}
interface shangke {
public abstract void sk();
}
interface beike {
public abstract void bk();
}
interface zuozuoye {
public abstract void zzy();
}
class teacher extends?ren implements gouwu, beike {
public void chifan() {
System.out.println(this.name + "在吃飯");
}
public void bk() {
System.out.println("在備課");
}
public void maidx() {
System.out.println("在買東西");
}
public void xuexi() {
}
}
class student extends ren implements zuozuoye, shangke {
public void xuexi() {
System.out.println(this.name + "在學(xué)習(xí)");
}
public void sk() {
System.out.println("在上課");
}
public void zzy() {
System.out.println("在做作業(yè)");
}
public void chifan() {
}
}
