Question: Given the Pet2Driver class below, write an abstract Pet2 class that contains just one iteman abstract declaration for a speak method. Also write Dog2 and
Given the Pet2Driver class below, write an abstract Pet2 class that contains just one item—an abstract declaration for a speak method. Also write Dog2 and Cat2 classes that extend Pet2, so that when you execute Pet2Driver and input ‘c’ or ‘d’, the program prints “Meow! Meow!” or “Woof! Woof” but if you input anything else, it does not print anything.
![import java.util.Scanner; public class Pet2Driver { public static void main(String[] args) { Scanner stdIn =](https://dsd5zvtm8ll6.cloudfront.net/images/question_images/1704/8/7/8/587659e61fbd0fed1704878586188.jpg)
import java.util.Scanner; public class Pet2Driver { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); Pet2 pet = null; System.out.print("Which pet are you addressing? " + "Enter c for cat or d for dog: "); switch (stdIn.nextLine().charAt(0)) { case 'c' -> pet = new Cat2(); case 'd' -> pet new Dog2(); } // end switch = if (pet != null) pet.speak(); } // end main } // end Pet2Driver
Step by Step Solution
3.52 Rating (155 Votes )
There are 3 Steps involved in it
To complete the task described we must create an abstract class Pet2 with an abstract speak method T... View full answer
Get step-by-step solutions from verified subject matter experts
