sad-ducky
sad-ducky

Reputation: 73

Issues with inheritance (java)

I was reading about how java avoids the deadly diamond of death, but i still have some questions. What if a class inherits a class and implements an interface and they each have a method with the same prototype? Or a method with the same name, same arguments, but different return types?

Thank you!

Upvotes: 0

Views: 298

Answers (1)

Chry Cheng
Chry Cheng

Reputation: 3468

What if a class inherits a class and implements an interface and they each have a method with the same prototype?

If you don't override the inherited method, the compiler will assume that it's your class' implementation of the interface method. This may not necessarily be correct. It depends on the superclass' implementation.

Or a method with the same name, same arguments, but different return types?

You won't be able to implement the interface method because the compiler will think you are trying to overload the superclass method with a different return type.

Upvotes: 3

Related Questions