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 ();
square.foo(“bar”);

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



Leave a Reply 7

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


Edward

Edward

I think all the answers are wrong . Because, The ture answer is
Square square = new Square ();
square.foo (“bar”);
square.foo();

And C AND B are same, maybe someone typied wrong.

Luise

Luise

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

One choice is missing.

Ivan

Ivan

Hi Luise,

Did you take this exam recently? Are these the actual questions? Thanks!

ming

ming

the correct answer is
Square square = new Square ();
square.foo(“bar”);
square.foo ();

Lucas

Lucas

Well I don’t think the question is asking to produce the results in order, which is a mistake because normally in these exams the order matter. but in case it is, there is really missing an option there, as others have commented above.

Jk

Jk

I think the wrong answer is given for question 55
it should be

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

Akash

Akash

one ans missing