GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Interview Questions  >  J2EE  >  Core Java

 Print  |  
Question:  we know that Object class is super class of every class & a class extends only one class. so
how is it possible to a class to extend other than Object class?





Answer: Because java supports multilevel inheritance.


November 11, 2005 08:09:19 #1
 Krishna Prasad J2EE Expert  Member Since: November 2005    Total Comments: 1 

RE: we know that Object class is super class of every...
 

case 1

suppose you have a class Test, which doesn't extend any other class. So by default, Object becomes it's super class.

                                   Object->Test

case 2

If your Test class wants to extend some other class, for example Hashtable, your class will become a sub class of Object through Hashtable because Hashtable is a subclass of Object. Any class you are trying to extend will be a subclass of Object directly or due to hierarchy. 

                                    Object->Map->Hashtable->Test

Object is the superclass of Test even when you have Test extend HahTable

So according to case 1 Test is a subclass of Object directly.

According to case 2 Test is a subclass of Object due to the hierarchy.

so no matter you extend a class or not, your class will always be a subclass of Object.

     

 

Back To Question