• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java Multiple Inheritance.

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Today me and my friend had a discussion, he argued that Java supports multiple inheritance by implementing many interfaces. I argued that by providing implementation for empty methods from interface, thats not going to be multiple inheritance, we are simply using method signatures from interface and its a contract between interface and class.

"My implementing an interface the class is promising that, it is going to provide implementation for all the methods in implemented interface."

Java does not support multiple inheritance by implementing many interfaces.

Pl. correct if I am wrong in my discussion with my friend.

Thanks & Regards,
Ganesh.
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would say that Java provides a limited version of multiple inheritence. However, it does not provide "complete" multiple inheritence like you see in other OO languages like C++ that allow you to inherit implementation as well as the interface.

Layne
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought that Java refrained people from doing multiple inheritance, because it's bad design and calls for problems. That is why you can extend only one class. I do not consider implementing interfaces as being inheritance.
Maybe wrong.
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ganesh,
You are correct. Implementing interfaces is not multiple inheritance.
With inheritance, the class is gaining funcionality from the base class. With implementation, the class is gaining no functionality - just the 'appearance'.
Inheritance is a 'is a' relationship.
Implentation is a 'looks like, but isn't' relationship.
I hope I explained that well.
--Dave
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://www.custommode.com/space/Multiple+Inheritance+in+Java
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"ddd aaa,"

Welcome to JavaRanch!

Please revise your display name to meet the JavaRanch Naming Policy. To maintain the friendly atmosphere here at the ranch, we like folks to use real (or at least real-looking) names. You can edit your name here. Thank you for your prompt attention!

-Marc

PS: Note that if class A implements an interface B, then an instance of A "is-a" B. Or as Bruce Eckel says in Thinking in Java, interfaces allow a "variation of 'multiple inheritance' by creating a class that can be upcast to more than one base type." (Page 316 of the new 4th edition.)
[ March 17, 2006: Message edited by: marc weber ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic