Big Data Sixth day job

Source: Internet
Author: User

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

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.