| Difference between Abstract class and Interface in Java
Below are the 9 main difference between Abstract Class and Interface when we ask about Java
(1)Abstract Class:-We can extend abstract class by using keyword "extends".
Interface:-We can implement interface by using keyword "implements".
(2)Abstract Class:-Here in this class have class members like Private, protected etc.
Interface:-Members of interface are public in default.
(3)Abstract Class:-Abstract keyword is used to declare abstract class.
Interface:-Interface keyword is used to declare interface.
(4)Abstract Class:-Abstract class not support multiple inheritance.
Interface:-Interface have feature to support multiple inheritance.
(5)Abstract Class:-Abstract class have abstract and non-abstract methods.
Interface:-Interface have only abstract methods and it have default and static methods both.
(6)Abstract Class:-Abstract Class can have final, non-final, static and non-static variables.
Interface:-Interface has only static and final variables.
(7)Abstract Class:-Abstract class have features which can provide the implementation of interface.
Interface:-But interface cannot provide the implementation of abstract class.
(8)Abstract Class:-An abstract class can extend another Java class and implement multiple Java interfaces.
Interface:-An interface can extend another java interface only.
(9)Abstract Class:- Example:-
public abstract class WebSites
{
public abstract void site1();
}
Interface:- Example:-
Public interface Drawable
{
void draw();
} | | |