1. Implement adapter pattern design using abstract classes and interfaces. The classes and interfaces involved are buttonlistener (interfaces), respectively,
It contains the click ()/Dbclick ()/keyUp ()/KeyDown () methods.
Buttonadapter (Button adapter class), the default implementation of the non-click () method in the adapter.
Add the AddListener (Buttonlistener L) method to the Button class.
Interface Buttonlistener
{
public void click ();
public void Dbclick ();
public void keyUp ();
public void KeyDown ();
}
Abstract class Buttonadapter implements buttonlistener{
public void Dbclick () {
}
public void KeyUp () {
}
public void KeyDown () {
}
}
Class Buttonlistener extends Buttonadapter
{
public void Click () {
SYSTEM.OUT.PRINTLN ("I click");
}
}
Class Button
{
Private Buttonlistener listener;
public void AddListener (Buttonlistener lsn) {
THIS.LISTENER=LSN;
}
public void clickb () {
Listener.click ();
}
}
Class Adapterdemonew
{
public static void Main (String [] args) {
button Btn1=new button ();
Buttonlistener blr=new Buttonlistener ();
Btn1.addlistener (BLR);
Btn1.click ();
}
}
Job 2
Explain what polymorphism is.
Why can functions be overwritten, and properties cannot be overwritten?
A: Polymorphism is a variety of forms, in succession, the parent class refers to the subclass object, Father S=new Son ();
interface, an interface that references the object created by the interface's class.
Because the property has data, it is the original, the function is constructed method, does not store the data, so it can be overwritten.
Big Data 6th day job