dcsimg
interface,pure abstract class
4 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   gennady_meltsin
Posted On:   Tuesday, June 5, 2001 06:27 AM

what is the difference between interface and pure abstract class

Re: interface,pure abstract class

Posted By:   John_Mitchell  
Posted On:   Sunday, June 17, 2001 03:47 PM

Re: interface,pure abstract class

Posted By:   Michael_Wax  
Posted On:   Tuesday, June 5, 2001 09:22 AM

Actually, interfaces and abstract classes are very different if you are trying to write clear object-oriented code.

  • Use an abstract class if you want to use inheritance. For example, the class Fruit would be abstract, and the classes Apple and Pear (which are types of fruit) would extend it and implement its methods.

  • Use an iterface if you want pure polymorphism. For example, both String and Integer implement the Comparable interface. You would not have String and Integer extend some abstract "comparable" class, because the inheritance relationship makes no sense in this case.


One of Java's great strengths is that it does provide a mechanism for pure polymorphism without inheritance. C++ does not provide this mechanism.

Re: interface,pure abstract class

Posted By:   Thanigai_Venkatesan  
Posted On:   Tuesday, June 5, 2001 07:52 AM



Hi Gennady Meltsin,
The difference between the Abstract Class and Interface :

1. When you extend an abstract class there is no need to implement all the methods of class where
as implementing the interface you have to implement all the methods.

2. And the other one is,even one method in a class is abstact you have to declare the class as abstract
class and the other methods can have implementation,but in the interface only method declarations allowed.

Regards

Re: interface,pure abstract class

Posted By:   Christopher_Schultz  
Posted On:   Tuesday, June 5, 2001 06:31 AM

They're functionally the exact same thing. The reason you'd choose one over the other is when you want to inherit the implementation of another class and yet implement the interface of the "pure abstract" class.



In that case, you'd prefer Java's interface type to an abstract base class with all abstract methods.



-chris
About | Sitemap | Contact