- We have a virtual
Buttonthat when clicked will call an abstract method onClick() of a listener interfaceOnClickListener. - We need to implement the onClick() so that it prints the
Buttonname.
OnClickListener.java
package com.hmkcode;
public interface OnClickListener {
void onClick(Button button);
}Button.java
package com.hmkcode;
public class Button {
private OnClickListener onClickListener;
private String name;
// click the button
public void click(){
this.onClickListener.onClick(this);
}
// getters & setters
}