18 程序改错题2 (5分)
程序改错题。以下代码存在错误,请修改后提交。
public class Main {
public static void main(String[] args) {
Animal animal = new Dog();
animal.shout();
animal.run();
}
}
class Animal {
void shout() {
System.out.println(“animal shout!”);
}
}
class Dog extends Animal {
void shout() {
super.shout();
System.out.println(“wangwang……”);
}
void run() {
System.out.println("Dog is running");
}
}
输入格式:
输出格式:
输入样例:
无
输出样例:
animal shout!
wangwang……
Dog is running
public class Main {
public static void main(String[] args) {
Animal animal = new Dog();
animal.shout();
((Dog) animal).run();
}
}
class Animal {
void shout() {
System.out.println("animal shout!");
}
}
class Dog extends Animal {
void shout() {
super.shout();
System.out.println("wangwang……");
}
void run() {
System.out.println("Dog is running");
}
}