2021-04-22

課堂代碼
public static void main(String[]args){
Doctor doctor = new Doctor();
doctor.shoushu();
doctor.eat();

    Nurse nurse = new Nurse();
    nurse.taKeCare();
    nurse.eat();
}

public class Doctor extends Person{
//做手術(shù)
public void shoushu(){
System.out.println("醫(yī)生在做手術(shù)");
}
}

public class Nurse extends Person{
//照顧病人
public void taKeCare(){
System.out.println("護士在照顧病人");
}
}

~
public class Person {
private String name;
private int age ;
//getter setter

//吃飯
public void eat(){
    System.out.println("在吃飯");
}

}
~
~
public static void main(String[]args){
UncleOne yuqian = new UncleOne();
yuqian.sendRedPacket();
yuqian.chouyan();

    /*UncleTwo uncleTwo = new UncleTwo();
    uncleTwo.sendRedPacket();
    uncleTwo.drinKWine();*/
    final Uncle uncle1 = new Uncle();
    //uncle1 = new Uncle();
    uncle1.setName("修改前的名字");
    System.out.println(uncle1.getName());
    uncle1.setName("再修改后名字");
    System.out.println(uncle1.getName());
}

~
~
public class Uncle {
private String name;
private int age;
// getter setter
public void setName(String name){
this.name = name;
}
public String getName(){
return name;
}
public void setAge(int age){
this.age = age;
}
public int getAge(){
return age;
}
//發(fā)紅包
public void sendRedPacket(){
System.out.println("舅舅在發(fā)紅包");
}
}
~
~
public class UncleOne extends Uncle{
public UncleOne(){
super(); //調(diào)用父類的構(gòu)造方法
System.out.println("子類大舅的構(gòu)造方法被創(chuàng)建了");
}
public void chouyan(){ System.out.println("大舅喜歡抽煙"); }

public void sensendRedPacket(){
    System.out.println("大舅家道中落,紅包只有一毛錢");
}

}

~
~
public class UncleTwo extends Uncle{
public void drinKWine(){
System.out.println("二舅喜歡喝酒");
}

}

~
不知道咋回事有的顯示,有的不顯示

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容