Java Reference
In-Depth Information
Because this Employee does not explicitly extend another class, it implicitly
extends Object. In fact, we could have added the extends keyword as follows:
public class Employee extends Object
{
//Class definition
}
If you write a class and do not explicitly extend another class, the
compiler adds “extends Object” to your class declaration. If you write a
class that extends another class besides Object, the class still is a child of
Object, since eventually one of its ancestors must have extended Object.
Suppose that a Salary class is written that extends Employee:
public class Salary extends Employee
{
//Class definition
}
The Salary class extends Employee, and because a Java class can only have
one parent class, Salary does not extend Object directly. Because Employee
extends Object, however, the Salary class is an indirect child of the Object class.
Note that the compiler does not add “extends Object” to a child class that
already extends another class.
The Methods of the Object Class
Object is a parent of every class, so the methods in the Object class are inher-
ited by every Java object. Therefore, the methods in the Object class can be
invoked on any Java object, no matter what class type the object is.
The following list contains the signatures of the methods in the Object class
and a description of what each method does:
public final Class getClass(). Every class used in a Java program is
loaded by the JVM. When the JVM loads a class, the information about
the class is stored in a Class object. Use this method to obtain a reference
to the Class object of the object you invoke the method on.
public int hashcode(). This method returns a hashcode value for the
object, which is useful when working with hash tables and other data
structures that use hashing.
Search WWH ::




Custom Search