File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A Question From TestLab

 
Neil Muya
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which of the following statements are true?(Choose three)

This is the box that i should checked.

"Interface "is-a" java.lang.Object"

This was the explanation:
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.


For what I know an interface does not extend the Object class..

hmmm or maybe i did not get the question right.

Hope you guys can help me with this thank you!
 
Neha Daga
Ranch Hand
Posts: 504
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read this in K&B:
In java everything that is not a primitive is an Object.
 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4117
195
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Neil Muya wrote:A Question From TestLab

TestLab ?
 
Simran Dass
Ranch Hand
Posts: 183
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


A small example for the explanation given in the EXAMLAB

java.io.Serializable sb = new String();
Object o = sb;


Hope now you get it
 
Rohan Kayan
Ranch Hand
Posts: 123
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is still not clear to me ,



In above example String "is-a" an Object that is why the assignment in second line worked. But how can we say that Interface "IS-A" java.lang.Object ?
 
raj malhotra
Ranch Hand
Posts: 288
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this:
 
rushikesh sawant
Ranch Hand
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All objects implicitly extends java.lang.Object.
Interface defines a set of methods that its implementing classes must implement.
here,



String class IS-A Serializable.
string class' object is-a serializable.
so, a particular object IS-A particular interface.
hence, Interface IS-A Object.

it is a logical IS-A relationship.
 
Parambir Singh
Ranch Hand
Posts: 40
Android Java Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If an object of type A can be cast to type B, we can say that 'A is a B'.

E.g. Object o = new String();
Hence, String "is a" Object

Serializable s = new String();
Hence, String "is a" Serializable

And, Object o = s;
Hence Serializable "is a" Object

And in the last statement, s can be an object implementing any interface, therefore Interface "is a" Object is true.
 
Rohan Kayan
Ranch Hand
Posts: 123
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this one is a better example to understand that Interfaces are compiled as .class files and every classes are itself an Object in Java , that is why Interfaces "IS-A" java.lang.Object
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic