Difference betweein Abstract Class and Interface
What is Abstract Class
An abstract class is a class that can’t be instantiated. It is only used to sub-classed. Other classes can inherit from it. The advantage of abstract is that it enforce rules for all the sub classes. Abstract class can have all the access modifiers.
What is Interface
Interface is like a class with no implementation. Interface only provides the signature of the method and properties. It is the duty of the class (which inherit the interface) to implement all the method of the interface. Interface is used in dot net to support multiple inheritance feature. A class can inherit only one class but can inherit many interface.A interface can only have public access modifier.
Difference betweein Abstract Class and Interface
Interface contains only signature but abstract can contain signature as well as implementation of the method
Interface can only have public access modifier. Interface is public by default . but a abstract class can have many access modifire. Abstract class can’t have selead modifier.
We have to implement all the methods of interface in its subclass but this condition is not there in case of abstract class.
The main difference between abstract class and interface is that a class can inherited from more than one interface but can inherit from only single abstract class.
Difference betweein Abstract Class and Interface
Subscribe to:
Post Comments (Atom)
Comments :
Post a Comment