Problem

Given the Pets3 program below, write an abstract Animal2 class that contains just one item...

Given the Pets3 program below, write an

abstract Animal2
class that contains just one item—an
abstract
declaration for a
speak
method. Write
Dog2
and
Cat2
classes that extend
Animal2,
so that when you run the Pets3 program and input either a ‘c’ or a ‘d,’ the program prints either “Meow! Meow!” or “Woof! Woof.”

import java.util.Scanner;public class Pets3{   public static void main(String[] args)   {     Scanner stdIn = new Scanner(System.in);     Animal2 animal;     System.out.print("Which type of pet do you prefer?\n" + "Enter c for cats or d for dogs: ");     if (stdIn.nextLine().charAt (0) = = 'c')     {        animal = new Cat2();     }     else     {        animal = new Dog2();     }     animal.speak();   } // end main}// end Pets3 class

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 14
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT