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

When I compile this program, it gives me the following answers: Ko Ko Cat says C

ID: 3574556 • Letter: W

Question

When I compile this program, it gives me the following answers:

Ko Ko Cat says Chung Lion Meow
Brina Tiger Cat says Roar
Ko Ko Cat says Meow
Zach Tiger Cat says Great Meow
Katherine Tiger Cat says Big Roar

I don't really understand the part where it says... ((Cat) a) .speak("Big"));

But can someone tell me step by step through these answers please?

abstract class Animal private String name; public Animal this "Animal" public Animal String name this. name name; public String to String return this.name; public abstract String speak class Cat extends Animal public Cat this Ko Ko" public Cat String name super name Cat" public String speak return "Meow"; public String speak String name return name Meow" class Tiger extends Cat public Tiger String name) super name Tiger public String speak return super. speak "Great" class Big Tiger extends Tiger public BigTiger super "Brina" public BigTiger String name) super name) public String speak return Roar public String speak String name return name Roar final class Lion extends Cat H public String speak return Chung Lion super. speak public String softer return Katherine super. speak public class Test14 public static void main String args) Animal a a new Lion System. out.println a says a. speak new Big Tiger System. out.println a says a spea a new Cat System. out.println a says a. speak a new Tiger "Zach" System. out.println a says a speak new Tiger Katherine Big System. out.println a says (Cat) a) speak Big

Explanation / Answer

Here The operation takes place is overriding. so

Animal a; // a is referening to Animal class

a = new BigTiger("Katherine"); // an object type BigTiger is assigned to a.

when we call ((Cat) a) .speak("Big")) no matter where the 'a' refers , it call BigTiger speak which has be last overrided.

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