Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java Program. Please answer the questions through a-d also please send me the wh

ID: 3726424 • Letter: J

Question

Java Program. Please answer the questions through a-d also please send me the whole code of the programalso the screenshot of the program running correctly. Thank you

Instructions:

The purpose of this laboratory experiment is to create a superclass and four subclasses, each subclass must override the superclass's methods to display specific properties different than the superclass using Java Program

Add a class that creates a new object for each class and calls the get methods.

Give an example of Inheritance by creating a SuperClass and four Subclasses.

(you have to follow the sample presented in class.)

Your classes must follow this hierarchy: Write the name class in the following chart.

Figure 1

Lab Report:

:

a)Description of the lab in your own words.

b)Source Code

c)Screenshots of you program running and results.

d)Write comments in your programs.

Super Class Name Subclass Subclass Subclass name name name Subclass name

Explanation / Answer

class Animal { // Super class

  

   private String name;

  

   public Animal(String name) {

       this.name = name;

   }

  

   public void sound(){

       System.out.println("General sound ...");

   }

}

class Cat extends Animal {// sub class of Animal

   public Cat(String name) {

       super(name);

   }

   // overriding

   public void sound(){

       System.out.println("Cat sound ...");

   }

  

}

class Dog extends Animal {// sub class of Animal

   public Dog(String name) {

       super(name);

   }

   // overriding

   public void sound(){

       System.out.println("Dog sound ...");

   }

  

}

class Horse extends Animal {// sub class of Animal

   public Horse(String name) {

       super(name);

   }

   // overriding

   public void sound(){

       System.out.println("Horse sound ...");

   }

  

}

class Tiger extends Cat {// sub class of Cat

   public Tiger(String name) {

       super(name);

   }

   // overriding

   public void sound(){

       System.out.println("Tiger sound ...");

   }

  

}

public class TestInheritance {

  

   public static void main(String[] args) {

      

       Animal a1 = new Cat("Cat");

       Animal a2 = new Dog("Dog");

       Animal a3 = new Horse("Horse");

       Cat c = new Tiger("TIger");

      

       a1.sound();

       a2.sound();

       a3.sound();

       c.sound();

   }

}

/*

Sample run:

Cat sound ...

Dog sound ...

Horse sound ...

Tiger sound ...

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote