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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.