class Animal{
public void sound() {
System.out.println("Animal is making a sound");
}
}
public class Cat extends Animal {
@Override
public void sound() {
System.out.println(" Meow");
}
public static void main(String[] args) {
Animal a = new Cat();
a.sound();
}
}
NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.
I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME
Examples: Example 1-Runtime Polymorphism: Lets say we have a class Animal that has a method sound()....
use the animal examples and recreate your animal project you created for the Polymorphism project and use interfaces instead of classes. ============================================================================= public class Animal { public void makeSound(){ System.out.println("“The animal is making a sound...”."); } } ============================================================================= public class Horse extends Animal { @Override public void makeSound() { System.out.println(" “Whinny”, “Neigh”or “Hi, I’m Mr. Ed.”"); } } ============================================================================= public class Cow extends Animal { @Override public void makeSound() { System.out.println(" “BoWow”, BoWoW, Cow Cow"); } } ============================================================================= public class...
PRG/421 Week One Analyze Assignment – Analyzing a Java™Program Containing Abstract and Derived Classes 1. What is the output of the program as it is written? (Program begins on p. 2) 2. Why would a programmer choose to define a method in an abstract class (such as the Animal constructor method or the getName()method in the code example) vs. defining a method as abstract (such as the makeSound()method in the example)? /********************************************************************** * Program: PRG/421 Week 1 Analyze Assignment * Purpose: Analyze the coding for...
In Java Which of the following statements declares Salaried as a subclass of payType? Public class Salaried implements PayType Public class Salaried derivedFrom(payType) Public class PayType derives Salaried Public class Salaried extends PayType If a method in a subclass has the same signature as a method in the superclass, the subclass method overrides the superclass method. False True When a subclass overloads a superclass method………. Only the subclass method may be called with a subclass object Only the superclass method...
C# - Inheritance exercise
I could not firgure out why my code was not working. I was
hoping someone could do it so i can see where i went wrong.
STEP 1: Start a new C# Console Application project and rename its main class Program to ZooPark. Along with the ZooPark class, you need to create an Animal class. The ZooPark class is where you will create the animal objects and print out the details to the console. Add the...
I need help for part B and C
1) Create a new project in NetBeans called Lab6Inheritance. Add a new Java class to the project called Person. 2) The UML class diagram for Person is as follows: Person - name: String - id: int + Person( String name, int id) + getName(): String + getido: int + display(): void 3) Add fields to Person class. 4) Add the constructor and the getters to person class. 5) Add the display() method,...
Status Topic Interfaces Description Video Scene Problem Consider a video scene in which we want to display several different types (classes) of objects. Let's say, we want to display three objects of type Deer, two objects of type Tree and one object of type Hill. Each of them contains a method called display. We would like to store their object references in a single array and then call their method display one by one in a loop. However, in Java,...