• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Classes not extending java.lang.object

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are there any classes which donot extend java.lang.Object?
If not, why are the methods in Object made protected instead of public?


Thanks,
Jitender.
 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The only classes which do not extend Object are the primitives (i.e. int, float, double, char, long, String).
 
Jitender Kumar
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Chris,
Primitives are not java objects. Hence java contains wrapper classes (java.lang.Integer etc., that also extends java.lang.Object) for int, char and other primitive types.

String is not a primitive type and it very much extends java.lang.Object.

http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html


Thanks,
Jitender.
 
Chris Allen
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the correction on String. I knew there were 8 in total so the other three I missed were short, boolean, and byte. Good question on the protected modifier. Perhaps they only want these methods to be called by objects and not the primitives.
 
Jitender Kumar
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jitender Kumar:
Are there any classes which donot extend java.lang.Object?
If not, why are the methods in Object made protected instead of public? ...


Good question! Indeed, all classes extend Object.

Two methods in Object (clone and finalize) have protected access. To understand why, see "using a trick with protected" from Appendix A in Bruce Eckel's Thinking in Java.
 
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Chris!

I have to assume you're studying for your SCJP exam - cool! In this thread I think you have some of your Java definitions a little sideways...ya wanna take another shot at your answers? I'm asking because we wouldn't want all the lurkers out there to be getting the wrong impression of how Java works
 
If you were a tree, what sort of tree would you be? This tiny ad is a poop beast.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic