- When we create an interface, we are basically creating a set of methods without any implementation that must be overridden by the implemented classes. The advantage is that it provides a way for a class to be a part of two classes: one from inheritance hierarchy and one from the interface.
- When we create an abstract class, we are creating a base class that might have one or more completed methods but at least one or more methods are left uncompleted and declared abstract. If all the methods of an abstract class are uncompleted then it is known as an interface. The purpose of an abstract class is to provide a base class definition for how a set of derived classes will work and then allow the programmers to fill the implementation in the derived classes.
- A class can inherit from only one class, but can implement any number of interfaces.
- Interface doesn't allow variables/constants to be declared but abstract class allows for declaration of variables and constants.
Difference between an interface and abstract class?
There are some similarities and differences between an interface and an abstract class. The differences between them...
Subscribe to:
Post Comments
(
Atom
)
0 comments :
Post a Comment