Question: Adopt a PetGiven the provided main ( ) method , create two ( 2 ) staticclasses inside of the HouseholdPets class. ( 1 ) Create

Adopt a PetGiven the provided main()method, create two (2) staticclasses inside of the HouseholdPets class.(1) Create HouseholdPetclass
Declare a String field called name (do notassign it a value and do not make it private)
Create a public constructor that takes in a String, and sets the field here.
Create a public method called describe()that prints out the following string:"This pet's name is "+ this.name +"."(2) Create DogPet class that extendsHouseholdPet
Declare a String field called sound
Create a public constructor that takes in a String, and sets the field here. Use the superkeyword to inherit the field name from HouseholdPet, like so: super(name);
Create a public void method for DogPetcalled describe() that prints the following:System.out.println("This dog's name is "+ this.name +", and they "+ this.sound +".");
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class HouseholdPets {
public static void main(String[] args){
Scanner in = new Scanner(System.in):
String name1= in.nextLine();
HouseholdPet pet = new HouseholdPet(name1);
String name2= in.nextLine();
String sound = in.nextLine();
DogPet dog = new DogPet(name2, "sound);
pet.describe();
dog.describe();
}// end of main()
/***** DO NOT CHANGE THE CODE ABOVE THIS LINE *****/
// WRITE YOUR CODE HERE
}

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 Programming Questions!