OOPS: interface vs abstract

srivmanish007 used Ask the Experts™
Exactly what could be the possible scenarions when we should make interface and when we shold go for abstract classes?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
More test questions.


I was expecting a solution from your side but i  thing it is waste to ask questions because no one is giving proper answers and sending to the sites'url which is not a better way.
I have queried about 5 questions but i have not got any one's answer just a got a story for all the questions.........
It's waste to effort the time as well as money on  this site to  get answers ithought that most  probably this site willl be helpful for  me but no ..................
Top Expert 2009
Hi srivmanish007,

Since you've received no good answers I'll try to help.

There are two key differences between a class and an interface.

1) Classes require hierarchy, and so sub-classes must belong to that hierarchy. interfaces do not require hierarchy and can be mixed in as needed. In the case of languages that do not allow multiple inheritance, then interfaces provide the alternative way to mix traits from multiple, unrelated ancestors, to a point, where you can only inherit from a single class at a time.

2) Interfaces do not provide implementation. Classes may. An abstract base class can define some default functionality, for example, some common variables or methods. An interface, however, is just a signature of methods that must be implemented.

Rule of thumb, when factoring out common behavior in a class hierarchy, use a class. When creating behaviour that may be used across unrelated classes, use an interface.

A class means, it is a duck, because its mother was a duck.
Interface means, if it quacks, it acts like a duck, so we treat it like one. A duck could also cluck like a chicken, by implementing the chicken interface as well.

Hope that helps.
anarki_jimbelSenior Developer

There are some good articles on internet about interfaces and abstract classes aimed on beginners. Please find some:




The first one has some code samples useful for understanding. Please read it - it's a good one.


no comments

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial