2

I have class A, and interfaces I, J, K and L

I then have AB and finally class C

class AB extends A

class C extends AB implements I, J, K, L

Interface I requires a method void setSize(int size).

Class A already has a method setSize(int size){this.size = size;}

Am I correct in saying I still have to override class A's setSize and implement setSize in class C to get the implementation correct?

2
  • 1
    Why do you think so? Do you get a compilation error? Commented Oct 30, 2014 at 19:53
  • 2
    FYI, I, J, K, and L are called Interfaces, not Implementations Commented Oct 30, 2014 at 20:04

2 Answers 2

2

If your class provides the method setSize(int) (matching the signature of the interface), then it will satisfy the interface requirements. If it inherits a matching method (not abstract) from a superclass, then it is provided; you don't need to override it.

Sign up to request clarification or add additional context in comments.

1 Comment

It was wierd my IDE was telling me I had to reimplement and giving me an error...but it was compiling ok. Then throwing non specific run time errors...but I am sure I can work through those. And sorry yes of course they are interfaces...my bad.
2

If any of superclasses has method with required signature, you don't need to implement it in your classes.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.