1. Implement adapter pattern design using abstract classes and interfaces.
public class button {private buttonlistener listener;public void AddListener (Buttonlistener listener) {This.listener = listener;} Public void click () {Listener.click ();}} Public interface buttonlistener {public void click ();p Ublic void dbclick (); Public void keyup ();p ublic void keydown ();} public abstract class buttonlisteneradapter implements buttonlistener{@Overridepublic void click () {system.out.println ("Default implementation of adapter-to-click Method");} @Overridepublic void dbclick () {system.out.println ("Default implementation of Adapter to Dbclick method");} @Overridepublic void keydown () {system.out.println ("Default implementation of Adapter to KeyDown method");} @Overridepublic void keyup () {system.out.println ("Default implementation of Adapter to KeyUp method");}} Public class mybuttonlistener extends buttonlisteneradapter{}public class main {public static void main (StRing[] args) {button b = new button (); Mybuttonlistener listener = new mybuttonlistener (); B.addlistener (listener); B.click ();}}
2. Describe what is polymorphic.
Why can functions be overwritten, and properties cannot be overwritten?
For:
A. What is polymorphic
Polymorphism is to look at the data from different angles, which form a variety of states of an object, such as: employees are characterized by salary and number
, but to look at the staff from a biological point of view is a nose with eyes. The object has not changed, just the angle of observation has changed, this is polymorphic.
B. Why a function can override a property but not
Attribute holds data and is an important asset that represents an object, so it can only be inherited but cannot be modified.
Big Data Sixth day job