"Big Data-Phase II" Java Foundation Sixth day job

Source: Internet
Author: User

[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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.