Question: JAVA - Type the program's output: public class TestAnimal { public static void main ( String [ ] args ) { Domestic myDomestic = new

JAVA
-
Type the program's output:
public class TestAnimal {
public static void main(String[] args){
Domestic myDomestic = new Domestic("Spot",8, "James");
Wild myWild = new Wild("Simba",6, "Lion");
myDomestic.printInfo();
System.out.println();
myWild.printInfo();
}
}
public abstract class Animal {
protected String name;
protected int age;
abstract void printInfo();
public String getNameAndAge(){
return this.age +" years, "+ name;
}
}
public class Domestic extends Animal {
private String owner;
public Domestic(String domesticName, int domesticAge, String domesticOwner){
this.name = domesticName;
this.age = domesticAge;
this.owner = domesticOwner;
}
public void printInfo(){
String nameAndAge = this.getNameAndAge();
System.out.println(nameAndAge);
System.out.println("Owner: "+ this.owner);
}
}
public class Wild extends Animal {
private String species;
public Wild(String wildName, int wildAge, String wildSpecies){
this.name = wildName;
this.age = wildAge;
this.species = wildSpecies;
}
public void printInfo(){
String nameAndAge = this.getNameAndAge();
System.out.println(nameAndAge);
System.out.println("Species: "+ this.species);
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!