Represents a generic user interface component that can respond to click actions.
@author
@author
@version
class UIElement{
Triggers the element's primary click action.
@return
public String click(){
return "Element clicked";
}
}
Represents a clickable button UI element.
@author
@author
@version
class Button extends UIElement{
{@inheritDoc}
@Override
public String click(){
return "Button clicked";
}
}
Represents a selectable checkbox UI element.
@author
@author
@version
class Checkbox extends UIElement{
{@inheritDoc}
@Override
public String click(){
return "Checkbox toggled";
}
}
Driver class demonstrating GUI polymorphism.
@author
@author
@version
public class GUIPolymorphismExample{
Handles click events for any polymorphic UI element.
@param element
public static void handleClick(UIElement element){
System.out.println(element.click());
}
Entry point for the GUI polymorphism application.
@param args
public static void main(String[] args){
UIElement button = new Button();
UIElement checkbox = new Checkbox();
handleClick(button);
handleClick(checkbox);
}
}