Hi, I have been wondering about how implementation/extension works :

Let me give you an example and then ask you my question :

public abstract interface A_int {}
public abstract interface B_int {}

public class A implements A_int, B_int {}

public class B extends A implements A_int

okay so here's my question :

Does class B also implement interface B_int?
I think yes, but I wanna make sure.
Thank you

Yes, and No. A implements, and so, by default, those methods are "available" through the B Class, since B is an A, but B, it self, does not, technically, implement the other interface.

Does class B also implement interface B_int?

What does the compiler say? Code a test and compile it and let us know the results.

First of all - every interface is by default abstract entity, so you shouldn't use special modifier (abstract keyword).

Second, saying in a structural way - yes - the class will be implements interface B_int, but not directly - it rather would extends A which must implements them after that all methods from interfaces became simple abstract methods.

So if you need to check fact of implementation in a case of reflection you need to go up in the inheritance tree or needs to use construction like this:

//..
TargetInterface.class.isAssignable( TargetClass.class );
//..

Thank you all. I got my answers.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.