Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essential SQLAlchemy Mapping Python To Databases

Authors: Myers, Jason Myers

2nd Edition

1491916567, 9781491916568

More Books

Students also viewed these Databases questions