I saw the below code under practice questions in SCJP book
Object obj = new Object();
First I thought it might be an error since I didn't use statement like this. Now I understand it is a valid statement.
I just want to understand what is the practical use of this if any. What can you use an object of the Object
type (rather than of a class derived from Object
) for?
Object
class?#equals
, and only classes provide implementations, interfaces cannot. classes that do not specify a parent inherit from object, so they all inherit these methods. This is important - e.g. for collections - as testing if the object is in the collection can never be left undefinedinterface
.