Questions about Abstract Classes and Interface (java)

Asked

Viewed 491 times

1

Before I express my doubt it is valid to make clear that in a certain way I understand the difference between the two.

I know that a abstract class can have implemented methods, attributes, constructors, and need at least one abstract method. Already an interface can only contain the signature of the methods. However, my doubt goes a little deeper..

I don’t know exactly when to use one or the other (example: Supposing my intention is to force my subclasses to implement certain methods... would an abstract class having these methods as abstract no longer solve this problem? So why would I use interfaces?).

That old example of the abstract class "Animal" and its subclasses: dog, cat, horse, etc.. I have seen Animal being used for example as interface and abstract class, in this type of case which would be the most appropriate and why?

  • Relevant: https://answall.com/q/90168/101. You can also provide more details: https://answall.com/q/87423/101 and https://answall.com/q/107524/101

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.