The reason that you are able to invoke that method through that variable of your interfce is because of a special treatment in case of interfaces in Java.
Even though the method is not explicitly declared in the interface, the special treatment implicitly provides declarations for all the public instance methods defined in the class Object
. And the toString
method is one of them.
But, note that interfaces don't implicitly extend any super interface (or class) unlike classes which implicitly extend the Object
class.
You will find a better explanation here - Do Interfaces really inherit the Object class in Java?
.