Question: Please write me an explanation I know I can run the code and get an answer but I want to understand it more. Thanks Inheritance
Please write me an explanation I know I can run the code and get an answer but I want to understand it more. Thanks
Inheritance and Polymorphism. Consider the following classes (System.out.println has been abbreviated as S.o.pln): public class Cup extends Box { public void method1() { S.o.pln("Cup 1"); } public void method2() { S.o.pln("Cup 2"); super.method2(); } } public class Pill { public void method2() { S.o.pln("Pill 2"); } } public class Jar extends Box { public void method1() { S.o.pln("Jar 1"); } public void method2() { S.o.pln("Jar 2"); } } public class Box extends Pill { public void method2() { S.o.pln("Box 2"); } public void method3() { method2(); S.o.pln("Box 3"); } } The following variables are defined: Box var1 = new Box(); Pill var2 = new Jar(); Box var3 = new Cup(); Box var4 = new Jar(); Object var5 = new Box(); Pill var6 = new Pill();
In the table below, indicate in the right-hand column the output produced by the statement in the left-hand column. If the statement produces more than one line of output, indicate the line breaks with slashes as in "a / b / c" to indicate three lines of output with "a" followed by "b" followed by "c". If the statement causes an error, fill in the right-hand column with the phrase "error" to indicate this. Statement Output var1.method2(); _________________________ var2.method2(); _________________________ var3.method2(); _________________________ var4.method2(); _________________________ var5.method2(); _________________________ var6.method2(); _________________________ var1.method3(); _________________________ var2.method3(); _________________________ var3.method3(); _________________________ var4.method3(); _________________________ ((Cup) var1).method1(); _________________________ ((Jar) var2).method1(); _________________________ ((Cup) var3).method1(); _________________________ ((Cup) var4).method1(); _________________________ ((Jar) var4).method2(); _________________________ ((Box) var5).method2(); _________________________ ((Pill) var5).method3(); _________________________ ((Jar) var2).method3(); _________________________ ((Cup) var3).method3(); _________________________ ((Cup) var5).method3(); _______________________
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
