[Job 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.
Pushbutton monitoring Interface Interface buttonlistener{ public void onclick (); public void ondbclick (); public void onkeyup (); public void onkeydown ();} //button Listener Adapter abstract class buttonadapter implements buttonlistener{ public void ondbclick () {} public void onkeyup () {} public void onkeydown () {}}class mylistener extends buttonadapter{ public void onclick () { System.out.println ("Click 1 Times"); } public void ondbclick () { system.out.println ("Click 2 times"); }}class button{//Button's listener private buttonlistener listener;//Adding listeners public void addlistener (buttonlistener l) { this.listener = l; } public void click () { listener.onclick (); } public Void dbclick () { listener.ondbclick (); }}class adapterdemo{ public static void main (String[] args) { mylistener ml = new mylistener (); button b = new button (); b.addlistener (ML); b.click (); &nBsp; b.dbclick (); }}
[Job 2]
------------------------------------
Explain what polymorphism is.
Why can functions be overwritten, and properties cannot be overwritten?
For:
Definition: The various forms of existence of a certain class of things.
For inherited classes, use the parent class type to refer to the object of the child class.
For an interface, you can use an interface to reference an object that is created by a class that implements the interface.
A property is an asset that holds data where the function is behaving, does not hold and stores data, so functions can be overwritten, and properties cannot.
This article is from the "Fan Penguin" blog, please be sure to keep this source http://xpenguin.blog.51cto.com/4912157/1772801
"Big Data-Phase II" Java Foundation Sixth day job