Does JAVA support multiple inheritance or not
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Hi Arulkumaran,
On a specific Interview i have been asked this question and till now i dont have any answers to get this one correctly / perfectly.
Q >> By default every class in Java inherits the "OBJECT" class , so any class is extended by this "OBJECT" class. If i try to extend some other class i think it is extended twice? Is this not multiple inheritance.
Eg: MyClass extends ParentClass (also extends Object class by default).
How this is managed / Or is this exceptional / How does JVM support only this inheritance?
--Naveen.
On a specific Interview i have been asked this question and till now i dont have any answers to get this one correctly / perfectly.
Q >> By default every class in Java inherits the "OBJECT" class , so any class is extended by this "OBJECT" class. If i try to extend some other class i think it is extended twice? Is this not multiple inheritance.
Eg: MyClass extends ParentClass (also extends Object class by default).
How this is managed / Or is this exceptional / How does JVM support only this inheritance?
--Naveen.
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
No, it is not multiple inheritance. It is a chain of single inheritance.
Put it this way: I can write class A which extends Object, Class B which extends A, and Class C which extends B. It's single inheritance all the way.
Put it this way: I can write class A which extends Object, Class B which extends A, and Class C which extends B. It's single inheritance all the way.
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Strictly speaking Don is right, you can only specify one class after the extends keyword.
But when you add interfaces into the mix it is possible to engage in multiple "contracts" - similar in many ways to extending several abstract classes that have abstract methods with no implementation.
I've seen many a thread of discussion on Java multiple inheritance !
But when you add interfaces into the mix it is possible to engage in multiple "contracts" - similar in many ways to extending several abstract classes that have abstract methods with no implementation.
I've seen many a thread of discussion on Java multiple inheritance !
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I think the answer should be "yes and no"
Java supports multiple inheritance in interfaces but not in implementations.
If asked why no multiple inheritance of implementations, then the answer is simply "simplicity". Java follows the age of C++, but is a stickler for OOP principles. Creators of Java wanted to get rid of the complexity of multiple inheritance (of implementations) that is inherent in C++.
Hope it helps
Java supports multiple inheritance in interfaces but not in implementations.
If asked why no multiple inheritance of implementations, then the answer is simply "simplicity". Java follows the age of C++, but is a stickler for OOP principles. Creators of Java wanted to get rid of the complexity of multiple inheritance (of implementations) that is inherent in C++.
Hope it helps
Sue
SCJP 1.2
SCWCD 1.4
SCBCD 5.0
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Sue's answer is the one I (and most other hiring managers I know) look for when asking that question.
--Mark
--Mark
Mark Herschberg, author of The Career Toolkit
https://www.thecareertoolkitbook.com/
James Bellan
Greenhorn
Posts: 9
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Thanks for all that answers Guys.
I am clear now.
I am clear now.
| Arch enemy? I mean, I don't like you, but I don't think you qualify as "arch enemy". Here, try this tiny ad: The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |










