• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Does JAVA support multiple inheritance or not

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 !
 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Author
Posts: 6055
8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sue's answer is the one I (and most other hiring managers I know) look for when asking that question.

--Mark
 
James Bellan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all that answers Guys.
I am clear now.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic