This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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.
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.
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.
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
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!
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 ]
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org