The BigBoss
The BigBoss

Reputation: 111

sub class does acquire the interface implemented by the superclass?

just a little question that can be stupid but i want to be sure of this. If i got 2 classes: ClassA and ClassB declared in this way

public ClassA implements Usable... //Usable is an interface obviously
...

public ClassB extends ClassA ...
...

Does ClassB implement Usable?

EDIT And if the answer is yes if i ll write this declaration below

public ClassB extends ClassA implements Usable 

what will happen ? eclipse doesn't show me errors but i want to know if there will be in some way

Upvotes: 0

Views: 54

Answers (2)

Sajan Chandran
Sajan Chandran

Reputation: 11487

public ClassB extends ClassA implements Usable is equivalent to just public ClassB extends ClassA. As you have already extended ClassA which implements all methods in your interface Usable, Eclipse wont show any errors (compilation) Both of these work:

Usable usable = new ClassA();
Usable usable = new ClassB();

Upvotes: 2

Suresh Atta
Suresh Atta

Reputation: 121998

Every Child is Parent.

So it is. You may not seeing it directly but those methods getting inherited .

Upvotes: 1

Related Questions