When a class implements an interface, does that make objects instantiated from the class be perceived as an object of that Interface?
i.e. Upon a class implementing the Runnable interface, does that make instances created from that class to be called a Runnable object?
So, where a Runnable object reference variable is expected (say, in the parameter of a method or a constructor), why is it legal that we can provide an instance of the class as an argument to that method or constructor? Is it because by implementing the interface, the class, is in essence, an object of the Interface?
Best How To :
An object of a class
C that implements an interface
I can be called an object of that interface, although a single object can be of many interfaces. Liskov substitution principle requires
C to be usable anywhere where
I is required, so in essence
I becomes a contract of
C, representing a subset of
Cs abilities, as applicable to a certain situation.
For example, when an object implements
run() method in the interface presents a particular aspect of the class to Java class library - namely, that objects of the class can be "ran" (by calling
run() on them). The presence of
Runnable lets you code the logic of your thread independently of Java designers, who write their thread-execution code independently of your implementation's logic.