Object
Object Class
All classes have a parent class (have a super class) except one.
The class at the top of the Java class hierarchy is called
Object.
If a class definition does not extend a parent class then
it automatically has Object as a parent class.
If a child class extends a parent class, then the parent
class either extends its parent
or automatically
extends Object.
Ultimately all classes have Object as an ancestor.
This means that all classes in Java share some common characteristics.
Those characteristics are defined in Object .
For example, all classes have a toString() method because the class Object
defines that method so all classes
get it by inheritance.
Of course, usually when you write a class you override the toString() method.
Constructors for our classes have not mentioned Object .
According to the rule, the compiler automatically does this:
// constructor
public Video( String ttl, int lngth )
{
super(); // use the super class's constuctor
title = ttl; length = lngth; avail = true;
}
This is correct.
Video automatically has Object as a parent class.
The compiler automatically does this:
class Video extends Object
{
. . .
}
Is it possible to write a class definition that does not
have Object as its ultimate ancestor?