Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Do all the classes extend the Object class?

 
Nittin singla
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to know if all the classes extend the Object class.
If yes, then how does this code compile. "class A extends Object{}" as the same class cant be extended twice.
If no then how am i able to override the hashcode ,equals methods that are defined in Object class...

Please clear my doubt.
TIA
 
Matthew Brown
Bartender
Posts: 4566
8
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, they do (ultimately - they may extend a class that extends a class that extends Object, etc). So if you don't have an extends declaration there's an explicit "extends Object". But you're allowed to declare it explicitly if you want - there's no point disallowing it as there's no conflict.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apart from the Object class of course
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
More about it here.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic