I am a Java beginner. I am little bit confused as to which is the Super class of all classes in Java?
From the Object
documentation:
The root class of the Java class hierarchy. All non-primitive types (including arrays) inherit either directly or indirectly from this class.
I believe it's java.lang.Object
java.lang.Object class is the super class for all java classes. you can see with following example:
class test
{
public static void main(String a[]){
System.out.println("hi this java");
}
}
save program with- test.java compile program using - javac test.java
now type following cmd to see real output ; javap test
output--
class test extends java.lang.Object{
test();
public static void main(java.lang.String[]);
}
the first line itself tells that by default it extends java.lang.Object.
java.lang.Object is a super class of any class by default.
Also Object class is a superclass for all interfaces by default, Ex
public interface ICommand
{
}
class Test {
ICommand c;
Object o = c; //works fine
}
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