Issues with inheritance (java)
I was reading about how java avoids the deadly diamond of death, but i still have some ques开发者_JAVA技巧tions. 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!
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.
精彩评论