Possible Duplicate:
Interface vs Abstract Class (general OO)
I'm not exactly clear on the difference.
Thanks
The Abstract class and Interface both are used to have abstraction. An abstract class contains an abstract keyword on the declaration whereas an Interface is a sketch that is used to implement a class.
An abstract class can contain static variables and methods. An interface contains only public static final variables.
Both Interfaces and Abstract Classes can have methods and variables, but neither of them can be instantiated. All the variables declared within the interface are final. However, the variables declared in Abstract Classes can be non-final and can be modified by the user-defined classes.
If you are creating functionality that will be useful across a wide range of objects, then you must use an interface. Abstract classes, at the end of the day, should be used for objects that are closely related. But the interfaces are best suited for providing common functionality to unrelated cases.
They are quite similar but there are some important technical differences:
These differences affect how the two techniques should be used:
An interface doesn't allow definition of any of the member methods, whereas an abstract class does allow some or all to be defined. A class however can only extend one class (abstract or not) but can implement as many interfaces as it wants.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With