What is the difference between an Interface and an Abstract class ?
Interface v/s Abstract class
All methods in an interface are implicitly abstract
Abstract class may contain both abstract and non-abstract methods.
A class may implement a number of Interfaces
Abstract class can extend only one abstract class
In order for a class to implement an interface, it must implement all its declared methods. However, a class may not implement all declared methods of an abstract class. Though, in this case, the sub-class must also be declared as abstract.
Abstract classes can implement interfaces without even providing the implementation of interface methods.
Variables declared in a Java interface is by default final.
An abstract class may contain non-final variables.
Members of a Java interface are public by default.
A member of an abstract class can either be private, protected or public.
No comments:
Post a Comment