Exam 1z0-808 All QuestionsBrowse all questions from this exam
Question 200

Given:

and the code fragment:

S2 sobj = new S2();

sobj.display(10, 100);

What is the result?

    Correct Answer: A

    D

Discussion
amit_lad88Option: A

The correct answer is A. it will print Child10 Child100 Parent100

Jess1985BOption: A

A is correct, tested

kuuuOption: A

Answer is A , straight forward

UAK94Option: A

Answer is A. class S1 { protected void display(int x) { System.out.println("Parent" + x); } } public class S2 extends S1 { public void display(int x, int y) { this.display(x); display(y); super.display(y); } public void display(int x) { System.out.println("Child" + x); } public static void main(String[] args) { S2 sobj = new S2(); sobj.display(10, 100); // Child10 Child100 Parent100 } }

iSnoverOption: D

The correct answer is letter D, a super has to be instantiated first in a method.

alex_au

JVM will automatically create a default constructor to initialize all fields (which in these cases there are no any attribute fields) so there will be no any compile time error.

Drift_KingOption: A

The answer is A, I tested. But why don't we get compilation error as super and this are supposed to be first statement in a constructor ? Can someone explain?

ManuTov

super.display() invoke S1 display method. need to be aware its not be using "super()". The same thing is happening with this.display() its invoke a method too, not be using "this()"

ManuTov

display() is been overloading & overriding. JVM will automatically create a default constructor to initialize all fields (which in these cases there are no any attribute fields)

carlosworkOption: A

Answer is A. UAK94 provided us the source code, in their comment.

alex_auOption: A

Answer should be A. The Main method not found is just the omitted part of this question.