Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Beginner
Jan 20, 1999

Inheriting From the Object Class

The Object class in Java is a superclass for all other classes defined in Java's class libraries, as well as for user-defined Java classes. In object-oriented terms, an object is an instance of a class. Note the distinction between the "Object class" and a Java "object": A Java object is an instance of any class derived from the Object class.

Normally, when a class is defined in Java, the inheritance from the Object class is implicit. Therefore, the following two declarations of class "MyClass" are equivalent:

 
public class MyClass
{
}

public class MyClass extends Object
{
}
In fact, the second class declaration is redundant and shouldn't be used. Note that inheriting from the Object class is the only exception to Java's rule for single inheritance. Java's inheritance mechanism allows a class to extend from only one superclass (although it may implement several interfaces). However, the following statement is valid, even though it implies that MyClass extends from two Java classes (the "Object" class and "Superclass"):
 
public class MyClass extends SuperClass
{
}
Ajit Sagar
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date