abstract class Pet{
protected String name;
public Pet(String n){
name = n;
}
public Pet(){}
public String getName(){
return name;
}
abstract String move();
abstract String speak();
public String toString(){
return "My pet " + name;
}
}
class Cat extends Pet{
public Cat(String n){
super(n);}
public String speak(){
return "miao miao";
}
public String move(){
return "run";
}
}
public class JLab0504A{
public static void main(String[] args){
Cat myCat = new Cat(a);
System.out.println(myCat.toString() + "\n" + "Speak: " +
myCat.speak() +"\n" + myCat.move() + " " +
myCat.getName() + "\n");
}
}
。。。。。我知道问题可能有点白痴。。。别喷我
protected String name;
public Pet(String n){
name = n;
}
public Pet(){}
public String getName(){
return name;
}
abstract String move();
abstract String speak();
public String toString(){
return "My pet " + name;
}
}
class Cat extends Pet{
public Cat(String n){
super(n);}
public String speak(){
return "miao miao";
}
public String move(){
return "run";
}
}
public class JLab0504A{
public static void main(String[] args){
Cat myCat = new Cat(a);
System.out.println(myCat.toString() + "\n" + "Speak: " +
myCat.speak() +"\n" + myCat.move() + " " +
myCat.getName() + "\n");
}
}
。。。。。我知道问题可能有点白痴。。。别喷我