Question: So I have a polymorphism & inhertiance problem, according to the solution given in class y . Do 3 and z . Do 3 should
So I have a polymorphism & inhertiance problem, according to the solution given in class yDo and zDo should both output an error but when I do it myself only yDo outputs an error and zDo outputs Do:lake Do:pond, can someone explain what is correct?
Consider the following class hierarchy:
public class Pond
Public void Do
System.out.printlnDo: Pond;
public class Lake extends Pond
Public void Do
System.out.printlnDo: Lake;
Do;
public class Bay extends Lake
Public void Do
System.out.printlnDo: Bay;
super.Do;
Public void Do
System.out.printlnDo: Bay;
public class Ocean extends Bay
Public void Do
System.out.printlnDo: Ocean;
Show the output after executing the following code:
public class MainClass
public static void main String Args
Lake X new Ocean;
Pond Y new Pond;
Pond Z new Lake;
Lake W new Bay;
Bay M new Ocean;
XDo;
Y Do;
Z Do;
W Do;
M Do;
X Do;
Y Do;
Z Do;
W Do;
M Do;
end main
end of MainClass
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
