Given the Pets3 program below, write an
abstract Animal2class that contains just one item—an
abstractdeclaration for a
speakmethod. Write
Dog2and
Cat2classes 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
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.