0

What an abstract class can do can be done by inheritance, so why use an abstract class?

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Surajit
  • 477
  • 3
  • 8
  • 16
  • 2
    Î assume you mean "interfaces"? – Lanbo Apr 27 '11 at 18:21
  • Class is eh... a class, inheritance is a concept. Please clarify your question... – Petar Minchev Apr 27 '11 at 18:21
  • possible duplicate of [Interface vs Abstract Class (general OO)](http://stackoverflow.com/questions/761194/interface-vs-abstract-class-general-oo) – Greg Apr 27 '11 at 18:22
  • abstract classes have been compared to every possible entity it's comparable to. Just look at the _Related Questions_. – Bala R Apr 27 '11 at 18:23
  • @scan i don't want to know this pls.i know this question is all over the site. – Surajit Apr 27 '11 at 18:24
  • http://stackoverflow.com/questions/2570814/when-to-use-abstract-classes This question is kind of like asking "what's the difference between a blueprint and physics" – Greg Apr 27 '11 at 18:30

2 Answers2

4

You can't compare them. They are different things.

You can achieve inheritance through abstract classes, which is one of the ways for inheritance, but you can't do a "vs" comparison on them.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
DarthVader
  • 46,241
  • 67
  • 190
  • 289
1

Assuming you actually mean 'interface' and not inheritance:

Abstract classes and interfaces provide a common model for derived classes to follow. If a class does not follow the definitions of the interface or abstract class, then it is not allowed to inherit the interface (or abstract class). The difference is that an interface is restricted to definitions only: properties, methods.

An abstract class, however, is not restricted to definitions only. An abstract class may contain full methods. An abstract class is intended to be able to execute required code that doesn't need to be fiddled with.

In many cases, the term interface is used to generally refer to both an Interface and an Abstract class.

IAbstract
  • 18,848
  • 14
  • 81
  • 137