Thursday, February 5, 2015

Difference between Interface and Abstract Class

Interface Abstract Class
Interface is nothing but contract of the system which can be implemented on classes. Abstract class is special kind of class that can not be instantiated but can be inherited.
A class may inherit several interfaces. A class may inherit only one abstract class.
An interface cannot provide any code, just the signature. An abstract class can provide signature as well as code to be overridden in the child classes.
Members of interface does not have any access modifier. Members of abstract class have an access modifier.
An interface can not contain fields, constructor, destructor. An abstract class can contain fields, constructor, destructor.
A class implementing an interface has to implement all the methods of the interface A class implementing an abstract class does not need to implement all the methods of the abstract class
If we add a new method to an Interface then we have to track down all the implementations of the interface and define implementation for the new method. If we add a new method to an abstract class then we have the option of providing default implementation and therefore all the existing code might work properly.
Reference can be created, it depends on child class object's memory. Reference can not be created.

No comments:

Post a Comment

Popular Posts