0

So I'm currently reading my java book and it doesn't seem to be to clear on the abstract classes and interfaces. Here is my understanding: Abstract classes are created to basically be the most generic form of a superclass, one of which no instance can be created, and an interface contains methods to be implemented by subclasses? Any help on what I'm missing to these aspects of coding. It would be greatly appreciated, thanks! (I'm not asking what is different between the two, I just want an understanding of what each is)

RiFF RAFF
  • 131
  • 2
  • 11
  • Interfaces are used to enforce a contract; these are method headers that any class that implements the interface must implement. Abstract classes are classes such as `List`, which have a basic set of properties and methods but cannot be instantiated. Classes can implement multiple interfaces but only extend one class. – wadda_wadda Oct 24 '15 at 21:41
  • What you are missing is the point that you should do "prior research" before posting a question here. Especially for such basics; do you really think you are the very first person to ever ask this question here? – GhostCat Oct 24 '15 at 21:42

1 Answers1

2

Well, all that interfaces do are state required implementation. A contract, if you will, that the inheriting class will implement their own versions of those methods with the same parameters and return values.

Abstract classes are similar, except they can implement generic implementation without requiring the inheriting classes to implement it.

Another difference is, that one class can implement multiple interfaces but only inherit from one possibly abstract class.

That's my understanding of it anyways. Hope I helped!

fuz
  • 88,405
  • 25
  • 200
  • 352
Matthew Chrobak
  • 384
  • 2
  • 8