ByteBrawl - With Extends And Implements - Abstract Classes - Inheritance

Abstract Classes - With Extends And Implements

Abstract classes can also extend other classes and implement interfaces. However, they don't actually have to have implementations for the abstract methods from either the class or the interface. However, whatever class extends the abstract class must implement all the abstract methods. Here's an example:

Animal.java

Main.java

Woah, that's a lot of classes! But it shows how abstract classes can be used in complex inheritance hierarchies. In this example, the Dog class remains abstract because it does not implement the play method from the Pet interface. The Labrador class, which extends Dog, is concrete, NOT abstract. So, it must implement the play method because Dog never did.

Loan Analogy

It's kind of like taking a loan. The debt you take on is the unimplemented abstract methods. You have to pay it back eventually (implement all abstract methods). But, if you pass the loan onto someone else (make your class abstract), they have to pay it back instead (they have to implement the abstract methods). And, people (classes) along the way can pay back part of the loan (override some of the abstract methods), or add even more debt (add more abstract methods).