Contents of the sixth day of big data

Source: Internet
Author: User

[Job 1]

------------------------------------

Use abstract classes and interfaces to design the adapter mode. The involved classes and interfaces are buttonlistener (interfaces ),

It contains methods such as click (), dbclick (), keyup (), and keydown.

Buttonadapter (Button adapter class), which defaults to non-click () methods.

Add the addlistener (buttonlistener L) method to the button class.


Code:

// Button listener Interface

Interface buttonlistener {

Public void onclick (); // click the event

Public void ondbclick (); // double-click the event

Public void onkeydown (); // press the key

Public void onkeyup (); // press the button to release

}


// Button

Class button {

// Button listener

Private buttonlistener listener;


// Add listener

Public void addlistener (buttonlistener LSN ){

This. Listener = lsn;

}


// Simulate a click event

Public void click (){

// Process the Click Event

Listener. onclick ();

}

// Simulate double-click events

Public void dbclick (){

Listener. ondbclick ();

}

}


// Button listener Adapter

Abstract class buttonlisteneradapter implements buttonlistener {

Public void ondbclick (){

}

Public void onkeyup (){

}

Public void onkeydown (){

}

}


Class mylistener extends buttonlisteneradapter {

Public void onclick (){

System. Out. println ("I click one! ");

}

}


Class yourlistener extends buttonlisteneradapter {

Public void onclick (){

System. Out. println ("You click one! ");

}

}


Class adapterdemo {

Public static void main (string [] ARGs ){

// Button1

Button btn1 = new button ();

Mylistener L = new mylistener ();

Btn1.addlistener (L );

Btn1.click ();


// Button2

Button btn2 = new button ();

Yourlistener yl = new yourlistener ();

Btn2.addlistener (yl );

Btn2.click ();

}

}


[Job 2]

------------------------------------

Describes what polymorphism is.

Why can I overwrite a function but not an attribute?


1) multiple forms.

For an inherited class, the parent class type is used to reference the object of the subclass.

The parent class calls subclass objects between classes with inheritance relationships and calls methods from different angles.

For an interface, you can use the interface reference to create an object for the class that implements the interface.


2) A function is a process or action. After the subclass inherits the parent class, it can override the parent class method,

After the corresponding content is called, it ends through the stack;

However, attributes belong to assets and store data. Therefore, functions can be overwritten, but attributes cannot.






This article is from the "11138113" blog. For more information, contact the author!

Contents of the sixth day of big data

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.