0

When to use an Interface and abstract class in Java? I've searched stackoveflow and came up with this answer. However, I'm unable to understand it without an example. Can someone help me with this?

interface: To implement a contract by multiple unrelated objects. When you want polymorphic behaviour for classes which are completely unrelated, use an interface

abstract class: To implement the same or different behaviour among multiple related objects. When you want to provide polymorphic behaviour in an inheritance hierarchy, use abstract classes.

G.Brown
  • 369
  • 3
  • 16
  • @G. Brown, as a suggestion, you can check my answer in https://stackoverflow.com/a/58697080/4148175. It is really an easy and straigh forward explanation – Jim C Nov 04 '19 at 16:07
  • 1
    @JimC I would like to know the exact scenario when to chose an Interface (or) abstract class – G.Brown Nov 05 '19 at 10:52
  • I believe there isn't such answer: use Interface for this case and Abstract for that case. Kindly, ready carefully the discussion provided above. Try to model/code the example I answered above and it will give a first idea (I am talking about the example for "movement" and "automobile" I have copied from certain book and pasted in my proposed answer) – Jim C Nov 06 '19 at 23:44

0 Answers0