|
INTERVIEW QUESTIONS
J2EE
JAVA
DETAILS
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: 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.
|
|
|
Category |
Java Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.3) By 8800 users |
Added on |
7/16/2011 |
Views |
67959 |
Rate it! |
|
|
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:
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. Source: CoolInterview.com
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
|
Related Questions |
View Answer |
|
What is JVM Heap Size? How does it affect the performance of the Application?
|
View Answer
|
|
How many JVM could be run on an operating system. if only one then what is the logical reason.
|
View Answer
|
|
What are differences between Enumeration, ArrayList, Hashtable and Collections and Collection?
|
View Answer
|
|
Which class is the super class for all classes in java.lang package?
|
View Answer
|
|
Why the container does not support multiple layout managers
|
View Answer
|
|
How to use JNI in java? and what are Struts and jini?and how to apply native code in java?
|
View Answer
|
|
Can wehave run() method directly without start() method in threads?
|
View Answer
|
|
When programmer using the vector and arrylist? and when ur using linkedlist and hashmap and hashtable?
|
View Answer
|
|
WHEN UR USING ARRAYLIST AND LIKEDLIST AND VECTOR AND HASHMAP AND HASHTABLE?
|
View Answer
|
|
if two overloaded methods are- Test(Object xyz) and test(Customer cust)[Assume Customer is a class with member name of type String].Now if we call test(null), which method will be called? why?
|
View Answer
|
|
How single threaded model works after implementation in class, basically architecture point of view.
|
View Answer
|
|
Is there any difference between Execution Engine and the JIT in java?
|
View Answer
|
|
If we have two public classes in a single java file ,how i have to give the name of the particular java file and how i can compile it?
|
View Answer
|
|
What is the difference between classpath and path variable?
|
View Answer
|
|
Strings are immutable.But String s="Hello"; String s1=s+"World"; S.O.P(s1); means printing "HelloWorld".How ?
|
String s1=s+"World"; S.O.P(s1); means printing - Java Interview Questions & Answers">
View Answer
|
|
What is the difference between interrupt() and join() in threads?Give an example program?
|
View Answer
|
|
Why there is no guarentee for System.gc() method will perform garbage collection for a particular time?
|
View Answer
|
|
Please Give me an example for User defined Exception
|
View Answer
|
|
what are the other ways to prevent a class from being subclassed.one way is to declare the class final. does declaring a class private prevent it from being subclassed?
|
View Answer
|
|
What is default Buffersize of any Bufferedclass?
|
View Answer
|