1

I am practising some exercises, and one question asked, name three differences between interface and abstract classes.

I wrote that interfaces are implementable and those classes that implement them than share a commonality. Interfaces contain abstract methods with no implementation. Therefore when classes implement interfaces must provide implementation for each of their methods. Classes can than be reused so long as they share those same methods, but not necessarily have any other commonalities other than that.

abstract classes can contain abstract and non abstract methods. However if one abstract method exists the entire class is considered abstract. Abstract classes are involved with inheritance and subclasses can extend from it, these subclasses can than contain any non abstract methods, and provide their own unique implementation for those abstract methods..

Not a 10/10 answer, but I'd like feedback on where I am right and obviously where I'm wrong. Thank you

interfaces can be implemented by any class, while abstract classes can only be extended from

interfaces contain methods where there is no implementation (aka abstract method) in any of the methods while abstract classes can contain abstract and non abstract methods

interfaces allow for unique classes to share a commonality while abstract classes only share commanlities with those subclasses they extend to

  • How about expressing your answer in the form requested. Not: this is an interface and that's an abstract class, but rather: interfaces do X which abstract classes don't. Three times. – Carl Manaster Nov 17 '13 at 02:41
  • @CarlManaster that prob would have gotten me a really poor mark, since I start off not answering the question rather I ramble on and on. Please see end of the question for my concise answer. – user2963817 Nov 17 '13 at 02:48
  • You are doing a great job and all points you mentioned are valid! Here's a link that may help http://stackoverflow.com/questions/1913098/what-is-the-difference-between-an-interface-and-abstract-class. I found this explanation especially helpful because it states the main idea behind the two. – slider Nov 17 '13 at 02:53
  • With the update, your answers are good. – Carl Manaster Nov 17 '13 at 03:09
  • possible duplicate of [Abstract Data Type and Interface](http://stackoverflow.com/questions/19239471/abstract-data-type-and-interface) – nawfal Jul 07 '14 at 10:08

0 Answers0