Hi ranchers, As i know Interfaces are same as abstract classes (if we include only abstract methods in abstract class). Then why there are two different things in java(interfeces n classes), though Abstract classes can do functions of interfeces? I mean to say why interface came in java, though there is abstract class for same purpose? Is it due to "MULTIPLE INHERITANCE" limitation of Classes? PLease reply... pras
Is it due to "MULTIPLE INHERITANCE" limitation of Classes?
Yes, that is exactly the only reason for the existance of interfaces in Java.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Joined: Jul 11, 2001
Originally posted by Naveen K Garg:
The GOF authers Erich Gamma himself explains there thinking and concept behind "Program to Interface not to Implementation".
I found this so far a best explaination for Interface and Abstract Class.
Read it again - Erich explicitely says that "programming to the interface" can be done using abstract classes.
In languages that support multiple class inheritance, purely abstract classes are indistinguishable from Java interfaces.
Naveen K Garg
Joined: Nov 28, 2005
I 100% agree with you.
But based my experience with various people, I found that they offten compare the general Interface term with Java Interface and hence the comfusion arise.
The link that I have give here does explain this difference.