Create a class called Animal with protected fields and a parameterized constructor to initialize the protected fields.
Fields:
  • name (String)
  • sound (String)
and Method:
  • public void makeSound()  - This method should display the name of the animal and the sound it makes.
Create a class called Dog that extends the Animal class.
The Dog class should have a constructor that accepts the name of the dog and sets the sound to "Woof".

Create a class called Cat that extends the Animal class.
The Cat class should have a constructor that accepts the name of the cat and sets the sound to "Meow".

Follow the naming convention as given in the main method of the suffix code.
Your last recorded submission was on 2024-03-09, 22:57 IST
Select the Language for this assignment. 
File name for this program : 
import java.util.Scanner;
// TODO: Create a class "Animal" that have a  parameterized constructor to initialize the protected fields and method of makeSound().
// Create a class called Dog that extends the Animal class.
// Create a class called Cat that extends the Animal class.
class Animal {
  protected String name;
  protected String sound;
  
  public Animal(String name, String sound) {
     this.name = name;
     this.sound = sound;
  }
  public void makeSound() {
     System.out.println(this.name + " says: " + this.sound);
  }
}
class Dog extends Animal {
    public Dog(String name) {
      super(name, "Woof");
    }
}
class Cat extends Animal {
    public Cat(String name) {
      super(name, "Meow");
    }
}
class W08_P1{
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
 
        String dogName = scanner.nextLine();
        String catName = scanner.nextLine();
 
        Dog dog = new Dog(dogName);
        Cat cat = new Cat(catName);
 
        dog.makeSound(); 
        cat.makeSound();  
 
        scanner.close();
    }
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
Jacky
Tom
Jacky says: Woof\n
Tom says: Meow
Jacky says: Woof\n
Tom says: Meow\n
Passed after ignoring Presentation Error