Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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 Building Microservices this week in the Design 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: 125

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%
Currently working on Scala at Knoldus Software
Ulf Dittmer
Rancher

Joined: Mar 22, 2005
Posts: 42958
    
  73
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."
Sidharth Khattri
Ranch Hand

Joined: Sep 16, 2013
Posts: 125

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.
 
Have you checked out Aspose?
 
subject: Doubt in interface question
 
It's not a secret anymore!