I read in a Java book that all classes in Java extend a class Object.
What is use of Object
class and why all classes extend it? Can anyone help me understand that?
Asked
Active
Viewed 235 times
1
3 Answers
3
Java guys were smart enough to implement the language make it eachier for program, Object
class is extended by all classes and benifits are :
- Giving some basic functionalities by default to all the classes. (such as toString, equals, hashcode, thread wait and notify functionality)
- Any type of object can be passed around as an arbitrary
Object
class object.(Generic collections have used it like hell.)
There may be some other uses, which I may not be aware of. :)

codingenious
- 8,385
- 12
- 60
- 90
1
Just inheritance theory applies here too.
Every class you use or write inherits the instance methods of Object.
So common methods that every actual Object must support are separated and defined in Object
class.
Note that there is default implementation for methods in Object ,So that you will not end up in writing basic functionality of your each class
.
Well written docs explained , what are those methods and why. Checkout here once Object as a Superclass

Suresh Atta
- 120,458
- 37
- 198
- 307