Question: public class Animal { //DO NOT MODIFY THIS CODE private String name; private int age; public String getName() { return name; } public void setName(String
public class Animal {
//DO NOT MODIFY THIS CODE
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age + 1;
}
public void setAge(int age) {
this.age = age;
}
}
-------------------------------------------------------------------------------------------------------------------------
//1. modify the Dog class so that it extends the Animal class. Don't redefine any of
//the existing attributes that are inherited from Dog (this is called shadowing
//and id a bad idea).
//2. add a String breed attribute to the Dog class (it should be private)
//3. write a toString method for the Dog class, that prints out all
//the attributes in a Dog (name, age, and breed), separated by spaces. You should use existing methods from the
//Animal class (but don't modify them)
//4. add a constructor to the Dog class that accepts a name, age,
//and breed as arguments, and stores these values.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
