This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in interface question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt in interface question" Watch "Doubt in interface question" New topic
Author

Doubt in interface question

Sidharth Khattri
Ranch Hand

Joined: Sep 16, 2013
Posts: 121

This is from diagnostic test on ExamLab, question number 6. I can't copy the text from there, but one of its correct answer states that "An interface "is-a" java.lang.Object".
But interface doesn't extend java.lang.Object class, how can their "is-a" relationship be true?
I've read that an interface does not extend java.lang.Object, it just implicitly declares all the methods in java.lang.Object class as public abstract.

This is the explanation given, but I can't understand it:
Answer-I is correct, because any object, which has an interface-reference, can be implicitly casted to a java.lang.Object reference, without doing any explicit cast.

Here is the screenshot of the queston:


OCPJP 6 - 96%
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41068
    
  43
I think it's just the wording that is a bit off. An interface is a concept - it doesn't exist in the JVM, and as such is not an object (or an Object).

Now, at runtime, if you have a reference with the type of an interface, that does point to an object, and thus can be cast to Object.

So maybe Answer I should be something like "An object of an interface type "is-a" java.lang.Object."


Ping & DNS - my free Android networking tools app
Sidharth Khattri
Ranch Hand

Joined: Sep 16, 2013
Posts: 121

Ulf Dittmer wrote:I think it's just the wording that is a bit off. An interface is a concept - it doesn't exist in the JVM, and as such is not an object (or an Object).

Now, at runtime, if you have a reference with the type of an interface, that does point to an object, and thus can be cast to Object.

So maybe Answer I should be something like "An object of an interface type "is-a" java.lang.Object."


Thanks for your response Ulf.
I hope I don't get this kind of ambiguous answer choice in the exam.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt in interface question
 
Similar Threads
Putting interfaces into objects
A Question From TestLab
John Hunt mock: Q30
Inheritance
Inheritance question - Interfaces