Bionix1441
Bionix1441

Reputation: 2319

Which class implements interface's method at runtime

If a method is declared in an interface (implemented by many classes), how to know at runtime which implementation this method uses.

Upvotes: 0

Views: 75

Answers (1)

Avi
Avi

Reputation: 21866

Assuming that's a hypothetical question, you can use getClass() method on the instance to get the concrete type of the implementing class.

But you probably should usually refrain from doing so. The whole idea of an interface is to abstract its implementation.

Upvotes: 3

Related Questions