0 votes
1.7k views
in Java by
What is the difference between interface and abstract class in java? Anyone can explain in detail.

1 Answer

0 votes
by

There are following difference between "abstract class" and "interface":

Abstract Class Interface
Abstract class declared with abstract keyword. Interface declared with interface keyword.
Abstract class has one or more abstract methods. All methods are declared with public abstract.
Abstract class can have instance methods that implements default behavior. Methods of interfaces are implicitly abstract and it cannot have implementations.
Abstract class should be extended using keyword “extends”. Interface should be implemented using keyword “implements”.
Abstract class can extend another class and implement multiple interfaces. Interface can extend another interface only.
Abstract class cannot be instantiated. Interface is absolutely abstract and it also cannot be instantiated.
Abstract class contains non-final variables also. Variables declared in interface is by default final.
Abstract class is more suited for code reuse and evolution perspective. Interface are better for Type declaration.
Abstract class we provide any default implementation in super class. When we add any new method in existing interface it breaks all its implementation and we need to provide an implementation in all classes which is implemented. This is not good.

 

Share:- Whatsapp Facebook Facebook


Welcome to Developerhelpway Q&A, where you can ask questions and receive answers from other members of the community.

Categories

...