Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in interface question

 
Sidharth Khattri
Ranch Hand
Posts: 125
Java Linux Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 125
Java Linux Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic