Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which class is super class of all classes

Tags:

java

android

I am a Java beginner. I am little bit confused as to which is the Super class of all classes in Java?

like image 489
user3153149 Avatar asked Jan 03 '14 14:01

user3153149


4 Answers

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.

like image 148
keyboardsurfer Avatar answered Oct 15 '22 18:10

keyboardsurfer


I believe it's java.lang.Object

like image 27
Si-N Avatar answered Oct 15 '22 17:10

Si-N


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.

like image 4
Atul Singh Rajpoot Avatar answered Oct 15 '22 16:10

Atul Singh Rajpoot


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
}
like image 3
AmitG Avatar answered Oct 15 '22 18:10

AmitG