vendredi 27 novembre 2015

is it possible to use an interface to speak to another class in java?

suppose i have Class A and class B and an interface called Message

public interface Message{
   public void sendMessage();
}

public class A implements Message{
   @Override
    public void sendMessage(){
      //call the sendMessage() in class B.
    }
}

public class B implements Message{
    @Override
     public void sendMessage(){
       System.out.println("Hola Stack!");
      }

 }

without a direct reference to class B can i somehow invoke the sendMessage() method in class B from class A?

Aucun commentaire:

Enregistrer un commentaire