求解一道java编程题,大神帮帮忙

题目如图
2024-11-03 02:35:26
推荐回答(1个)
回答1:

public class Human {


public String name;

public int age;


// 无参构造

public Human() {

super();

}


// 带参构造

public Human(String name, int age) {

super();

this.name = name;

this.age = age;

}


public void walk() {

System.out.println(name + "正在行走");

}


}

===============上面是Human类===============


public class Child extends Human {


private String schoolName;


// 有参构造

public Child(String name, int age, String schoolName) {

super(name, age);// 用父类的构造方法

this.schoolName = schoolName;

}

public void study() {

System.out.println(super.name + "在" + schoolName + "认真地学习");

}

@Override

public void walk() {

super.walk();

}

}

===============上面是Child类===============

public class Demo {


public static void main(String[] args) throws Exception {

Child child = new Child("小明", 9, "希望小学");

child.study();

child.walk();

}


}

===============上面是Demo类===============

Demo类执行情况

===============上面是Demo类的执行情况===============