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 y.Do3 and z.Do3 should both output an error but when I do it myself only y.Do3 outputs an error and z.Do3 outputs Do3:lake ->Do2:pond, can someone explain what is correct?
Consider the following class hierarchy:
public class Pond {
Public void Do2(){
System.out.println(Do2: Pond);}
}
public class Lake extends Pond {
Public void Do3(){
System.out.println(Do3: Lake);
Do2(); }
}
public class Bay extends Lake {
Public void Do1(){
System.out.println(Do1: Bay);
super.Do2();
}
Public void Do2(){
System.out.println(Do2: Bay);
}
}
public class Ocean extends Bay {
Public void Do2(){
System.out.println(Do2: 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();
X.Do2();
Y. Do2();
Z. Do2();
W. Do2();
M. Do2();
X. Do3();
Y. Do3();
Z. Do3();
W. Do3();
M. Do3();
}// end main
}// end of MainClass

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!