This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Multiple Inheritance.

 
Ganesh Prakhya
Ranch Hand
Posts: 76
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Layne Lund
Ranch Hand
Posts: 3061
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Dave Tuttle
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
ddd aaa
Greenhorn
Posts: 2
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic