Big Data 6th day job

Source: Internet
Author: User

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

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.