Tuesday, June 3, 2008

why both interface and an abstract class

An interface can have no implementation.

An abstract class can have some implementation as well as abstract methods which doesn't have implementation.

We have abstract classes to have the benefit of both the interface and a class.

In an abstract class, functionalities common for a module can be implemented in the methods, at the same time the methods that must be implemented by the classes specific for an operation can also be specified/enforced.

So an abstract class is an additional facility rather than a necessity, a nice to have feature in any OO language like Java.

No comments: