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?
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");
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With