What is the result?

Given:

interface Event {

String type = “Event”;

public void details();

}

class Quiz {

static String type = “Quiz”;

}

public classPracticeQuiz extends Quiz implements Event {

public void details() {

System.out.print(type);

}

public static void main(String[] args) {

new PracticeQuiz().details();

System.out.print(” ” + type);

}

}

What is the result?

Given:

interface Event {

String type = “Event”;

public void details();

}

class Quiz {

static String type = “Quiz”;

}

public classPracticeQuiz extends Quiz implements Event {

public void details() {

System.out.print(type);

}

public static void main(String[] args) {

new PracticeQuiz().details();

System.out.print(” ” + type);

}

}

What is the result?

A.
Event Quiz

B.
Event Event

C.
Quiz Quiz

D.
Quiz Event

E.
Compilation fails



Leave a Reply 8

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


Boris

Boris

I think the answer has to be E, because System.out.print(type);// The field type is ambiguous

Yury

Yury

I know certainly, E is correct.

Rudi

Rudi

You’re right.

E is the correct answer.

The field type is AMBIGUOUS !!!

Tested in Eclipse !!! 😀

Serg

Serg

+1
E. Compilation fails

System.out.print(type);// The field type is ambiguous
System.out.print(” ” + type);// The field type is ambiguous

Ray

Ray

I agree, E is correct.
Because a field in interface is final static.