Both of them provides abstraction and we have to give their implementation in their child classes so what's exactly is the difference between them and also please suggest me some scenario where i can use them.
Difference between Interfaces and Abstract Class
Collapse
X
-
Difference between Interfaces and Abstract Classes
When we declare any method inside the Interface it is implicitly abstract in other words we can say that you cannot give a definition of a method inside the interface because it would be an error BUT this is not the case with Abstract Classes, it can and cannot contain abstract methods.
Note - There should be at least one abstract method in an Abstract Class -
Abstract Class
An abstract class may contain concrete method.
To use an abstract class, you need to inherit it. Provide body to (override) the abstract methods if there are any.
Members of an abstract class can be public, private, protected or default.
Example:
InterfaceCode:public abstract class Shape{ public abstract void draw(); }
All the methods of an interface are abstract.
To use an interface you need to implement the interface and provide body to (override) all the abstract methods of it.
All the members of the interface are public by default.
Example:
Code:public interface Drawable{ void draw(); }Comment
Comment