• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A Question From TestLab

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I read this in K&B:

In java everything that is not a primitive is an Object.

 
Sheriff
Posts: 7134
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Neil Muya wrote:A Question From TestLab


TestLab ?
 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this:
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 40
Android Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic