4

Possible Duplicate:
Need for Abstract Class as well as Interface?

why do we need interface when we have abstract class ?

Answer : The only purpose for having interface is to achieve Multiple inheritance

Correct me if i am wrong

Community
  • 1
  • 1
Hari
  • 397
  • 1
  • 9
  • 23
  • 1
    `interfaces` favour simplicity. Using them ensures you are only importing an API description, not state or functionality (until we have virtual extensions on interfaces ;) – Peter Lawrey Mar 30 '12 at 16:29

2 Answers2

2

Favour implements over extends.

Implementing an interface is more flexible that extending an abstract class. You can only extend a single class but you can implement many interfaces.

Vincent Ramdhanie
  • 102,349
  • 23
  • 137
  • 192
  • @Vincent: so you confirm the OP's opinion ("The only purpose for having interface is to be able to implement several of them"), right? – Vlad Mar 30 '12 at 16:28
1

There's lots of similar questions here on SO.

Why is programming to abstract classes instead of interfaces wrong?

I've answered here on the pros and cons of each, you might want to check it out.

Community
  • 1
  • 1
pcalcao
  • 15,789
  • 1
  • 44
  • 64