Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default class that is extended by all classes in java

Is there any Default Class that is extended by all the classes by default in Java?

Example: If I have a simple class like:

Class A {
  String a;
}

Is this class extending a class by default?

like image 554
Pramod Ravikant Avatar asked Jun 19 '13 09:06

Pramod Ravikant


2 Answers

java.lang.Object class is superclass of all classes.

Class Object is the root of the class hierarchy. Every class has Object as a superclass. All objects, including arrays, implement the methods of this class.

You can test it :

A a = new A();
if(a instanceof Object){
  System.out.println("Object is superclass of all classes");
} 
like image 194
AllTooSir Avatar answered Sep 28 '22 07:09

AllTooSir


In Java, everything (apart from the plain old data types; int, boolean, double etc.) is implicitly derived from java.lang.Object.

In particular, the class contains useful functions such as lock() and notify() which are used in thread synchronisation.

For a full list, see http://docs.oracle.com/javase/6/docs/api/java/lang/Object.html

like image 41
Bathsheba Avatar answered Sep 28 '22 08:09

Bathsheba