I recently saw implementing where a interface is implemented in a class and in another class we have a static final variable of the interface type and it somehow was able to complete computation from the class that had implemented the interface .
My question is how will the interface variable handle this if more than one class has a implementation of the interface. Am I missing something or it is just guessing where the implementation of interface is .
This is for java language
public interface DemoMe{
  public void doSomething();
}
public class MainClass implements demoMe {
   public void doSomething(){
     System.out.println("Something was done ");
   }
}
public class AnotherClass { 
  private final DemoMe demoVariable;
  public void useMe(){
    demoVariable.doSomething();
   }
}
here the AnotherClass somehow knows how to look for implementation of doSomething. can someone point me towards how this exactly works.
 
    