Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Please explain exactly where we should use Interface and where to use Abstract Class. Great if you provide practical implementation.
Posted

Hi,

The main difference between the abstract and interfaces are

We use Abstract classes in the case where we want that the child class must override all the functions of the parent class.

But in the case of Interface this is not necessary i.e if we do not want to override any function of parent class we can declare interface and inherit our class from it.
 
Share this answer
 
Comments
PIEBALDconsult 7-Aug-13 0:44am    
"must override all the functions of the parent class"

Untrue.
Sarabjot Singh Makkar 12-Aug-13 23:36pm    
sir it is untrue in the case if the derived class is also an abstract class and i am assuming that the child class is normal child class
Abstract class : Doesn't allow to create the instance.
Provides basic functionality.
Reuse of code.
Can be used to consolidate and share functionality
e.g.Animal is abstract type and cat,dog,pig are concrete types.

Interface : Doesn't contain any logic.
Specifies type also.
Provides common functionality shared by different instances.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900