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{
//做手术
public void shoushu(){
System.out.println("医生在做手术");
}
}

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;
}
//发红包
public void sendRedPacket(){
System.out.println("舅舅在发红包");
}
}
~
~
public class UncleOne extends Uncle{
public UncleOne(){
super(); //调用父类的构造方法
System.out.println("子类大舅的构造方法被创建了");
}
public void chouyan(){ System.out.println("大舅喜欢抽烟"); }

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

}

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

}

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

你可能感兴趣的:(2021-04-22)