This week's book giveaways are in the iOS and Features new in Java 8 forums. We're giving away four copies each of Barcodes with iOS: Bringing together the digital and physical worlds and Core Java for the Impatient and have the authors on-line! See this thread and this one for details.
Classes can implements multiple interfaces. This is possible because even if a equally-named method is declared in both of them, the JVM don't get mad choosing which implementation to use. There is only one... Interfaces is more about giving a class a different... "face" if you want
On the other side you cannot say the same for inheritance. If class A has a method implementation (let's say doSomething()) and class B another implementation of a method with the same name as class A (again, doSomething())... and you make class C extend both of them...and C inherits both implementations because the 2 were both public... Once you write something like: , what do you think the JVM would do? Which specific implementation would you use? This problem is better known as Deadly Diamond of Death (cause of the picture you get if you write it in an UML class diagram).
Hope it's clearer now [ June 23, 2007: Message edited by: Bianchi Francesco ]
Originally posted by Remko Strating: Java doesn't support multiple inheritance so the problem which you describe with inheritance doesn't occur in JAVA.
Thank you...I forgot to explicitely underline it...but that is what I was tryng to explain I cited the problem just to make it clearer why Java allow multiple interface inheritance and implementation while forbids class one.
Joined: Jun 04, 2007
Thanks everyone for your inputs... That's clear now..
hello i'm new here in this message board. i need some help. can anyone direct me to where i can post some basic beginner's questions concerning Java programming? actually i needed to know if there is any site where i can become a member and upload any new Java Program that i make and take part in competitions. please let me know, it would be very helpful
Originally posted by Shyam Prasad Murarka: ...And if I switch the return type to void, I get error that it dosen't fulfill the request for the other interface...
I'm not sure what you mean by that. This works for me...
Remember, you can't have methods in the same class that differ only by return type. And if a method's return type is void, then you can't try to return something (even a null reference).
Shyam Prasad Murarka
Joined: May 02, 2005
Dear Readers, What I had meant was that if in my implementation of the Sunali class I had changed the return type to void then the compiler would complain that I had not satisfied the Programmer interface. Anyway methods are not differentiated by their return type, which I had overlooked.