(Solved):(b) Polymorphism: Implement the Speaker interface: public interface Speaker { public void speak(); public void announce(String str); } Then, create three classes that implement Speaker in var… View Answer…

 

Question

(b) Polymorphism:

Implement the Speaker interface:

public interface Speaker {

public void speak();

public void announce(String str);

}

Then, create three classes that implement Speaker in various ways:

SpeakerOfTheHouse: speak method prints “I am Speaker of the House.”, and the announce method takes the name of a bill in the form of a string and prints it in the sentence “The [bill] has passed!”

SportsAnnouncer: speak method prints “Goal!”, and the announce method takes the name of a

Scroll to top