Test the follow code step by step and describe the working and purpose of following code. Add enough detail to justify the use of OOP concepts in this examples. Finally show the output of following code: interface Bird { public void fly(); public void makeSound(); } class Sparrow implements Bird { public void fly() { System.out.println("Flying"); } public void makeSound() { System.out.println("Chirp Chirp"); } } interface ToyDuck { public void squeak(); } class PlasticToyDuck implements ToyDuck { public void squeak() { System.out.println("Squeak"); } } class BirdAdapter implements ToyDuck { Bird bird; public BirdAdapter(Bird bird) { this.bird = bird; } public void squeak() { bird.makeSound(); } } %%%%%%%%%%%%%%%%%%MAIN%%%%%%%%%%%%%%%%%%%%%%%%%% class Main { public static void main(String args[]) { Sparrow sparrow = new Sparrow(); ToyDuck toyDuck = new PlasticToyDuck(); ToyDuck birdAdapter = new BirdAdapter(sparrow); System.out.println("Sparrow..."); sparrow.fly(); sparrow.makeSound(); System.out.println("ToyDuck..."); toyDuck.squeak(); System.out.println("BirdAdapter..."); birdAdapter.squeak(); } }
Test the follow code step by step and describe the working and purpose of following
code. Add enough detail to justify the use of OOP concepts in this examples. Finally show the
output of following code:
interface Bird
{
public void fly();
public void makeSound();
}
class Sparrow implements Bird
{
public void fly()
{
System.out.println("Flying");
}
public void makeSound()
{
System.out.println("Chirp Chirp");
}
}
interface ToyDuck
{
public void squeak();
}
class PlasticToyDuck implements ToyDuck
{
public void squeak()
{
System.out.println("Squeak");
}
}
class BirdAdapter implements ToyDuck
{
Bird bird;
public BirdAdapter(Bird bird)
{
this.bird = bird;
}
public void squeak()
{
bird.makeSound();
}
}
%%%%%%%%%%%%%%%%%%MAIN%%%%%%%%%%%%%%%%%%%%%%%%%%
class Main
{
public static void main(String args[])
{
Sparrow sparrow = new Sparrow();
ToyDuck toyDuck = new PlasticToyDuck();
ToyDuck birdAdapter = new BirdAdapter(sparrow);
System.out.println("Sparrow...");
sparrow.fly();
sparrow.makeSound();
System.out.println("ToyDuck...");
toyDuck.squeak();
System.out.println("BirdAdapter...");
birdAdapter.squeak();
}
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images