DerivedClass
public class DerivedClass extends SuperClass{
//name and breed
private String name;
private String breed;
public DerivedClass(String animalName){
super("Dog");
name = animalName;
breed = "Unknown";
}
//animal constructor
public DerivedClass(String animalName,String animalBreed){
super("Dog");
name = animalName;
breed = animalBreed;
}
//convert to string
public String toString(){
return super.toString() +"\n"+name+"is a"+breed+"type of dog.\n";
}
}
No comments:
Post a Comment