What should statement1, statement2, and statement3, be respectively, in order to produce the result?

Given:

public class SuperTest {
public static void main(String[] args) {
statement1
statement2
statement3
}
}
class Shape {
public Shape() {
System.out.println(“Shape: constructor”);
}
public void foo() {
System.out.println(“Shape: foo”);
}
}
class Square extends Shape {
public Square() {
super();
}
public Square(String label) {
System.out.println(“Square: constructor”);
}
public void foo() {
super.foo();
}
public void foo(String label) {
System.out.println(“Square: foo”);
}
}

What should statement1, statement2, and statement3, be respectively, in order to produce the result?
Shape: constructor
Square: foo
Shape: foo

Given:

public class SuperTest {
public static void main(String[] args) {
statement1
statement2
statement3
}
}
class Shape {
public Shape() {
System.out.println(“Shape: constructor”);
}
public void foo() {
System.out.println(“Shape: foo”);
}
}
class Square extends Shape {
public Square() {
super();
}
public Square(String label) {
System.out.println(“Square: constructor”);
}
public void foo() {
super.foo();
}
public void foo(String label) {
System.out.println(“Square: foo”);
}
}

What should statement1, statement2, and statement3, be respectively, in order to produce the result?
Shape: constructor
Square: foo
Shape: foo

A.
Square square = new Square(“bar”);
square.foo(“bar”);
square.foo();

B.
Square square = new Square(“bar”);
square.foo(“bar”);
square.foo(“bar”);

C.
Square square = new Square();
square.foo();
square.foo(“bar”);

D.
Square square = new Square();
square.foo(“bar”);
square.foo();

E.
Square square = new Square();
square.foo();
square.foo();

Explanation:
Incorrect answers:
A: Produces
Shape: constructor
Square: constructor
Square: foo
Shape: foo
B: Produces
Shape: constructor
Square: constructor
Square: foo
Square: foo
C: Produces
Shape: constructor
Shape: foo
Square: foo
E: Produces
Shape: constructor
Shape: foo
Shape: foo



Leave a Reply 4

Your email address will not be published. Required fields are marked *


Jazz

Jazz

“D” – Gives the Result
Shape: constructor
Square: foo
Shape: foo

Explanation:
A –
Shape: constructor
Square: constructor
Square: foo
Shape: foo

B-
Shape: constructor
Square: constructor
Square: foo
Square: foo

C-
Shape: constructor
Shape: foo
Square: foo

E-
Shape: constructor
Shape: foo
Shape: foo

James

James

The Answer is D.

Tommy

Tommy

I confirm that the answer is D.