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

What is printed by running the DoSomething class? public class Figure { public v

ID: 674400 • Letter: W

Question

What is printed by running the DoSomething class?

public class Figure {

public void display() {

System.out.print("Figure");

}

public void display(String s) {

System.out.print("Figure" + s);

}

}

public class Rectangle extends Figure {

public void display() {

super.display();

System.out.print("Rectangle");

}

public void display(String s) {

System.out.print("Rectangle" + s);

}

}

public class Square extends Rectangle{

public void display() {

super.display();

System.out.print("Square");

}

public void display(String s) {

System.out.print("Square" + s);

}

}

public class DoSomething {

public static void main(String[] args) {

Figure f = new Figure();

f.display();

f.display(“One”);

f = new Rectangle();

f.display();

f.display(“Two”);

f = new Square();

f.display();

f.display("Three");

}

}

Explanation / Answer

Figure:

1. f.display(): Figure

2. f.display("One"): FigureOne

Rectangle:

3. f.display(): FigureRectangle

4. f.display("Two"): RectangleTwo

Square:

5. f.display(): FigureRectangleSquare

6. f.display("Three"): SquareThree

So, the final output of the program is:

FigureFigureOneFigureRectangleRectangleTwoFigureRectangleSquareSquareThree

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