Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What will this program output? 2 What will be printed by the following code? Con

ID: 3744000 • Letter: W

Question

What will this program output?

2 What will be printed by the following code? Consider he polymorphic invocation. (G pts) public class Inherit class Figure void display) System.out printlIn("Figure") class Rectangle extends Figure void display) System,out printin ("Rectangle") class Box extends Figure void display) System.out printin("Box"): Inherit(0 Figure f new Figure ): Rectangle r new Rectanglet) Box b- new Box ) .display) s- ri f.display); t b: t.display): Write Output Here public static void main(StringI) args) new InheritD

Explanation / Answer

The output contains 3 lines given below
Figure
Rectangle
Box


-----------
Explanation
------------
Since both Rectangle and Box inherit from Figure class, the objects of these classes can be assigned to variable f of Figure type. The display() function is overriden in both Rectangle and Box and these new definitions are called instead of the one in the Figure class

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote