Search code examples
javainterfaceabstract-classsuperclass

Can someone help explain abstract classes and interfaces to me (novice)?


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)


Solution

  • 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!