Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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: 9034
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
 
Watchya got in that poodle gun? Anything for me? Or this tiny ad?
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic