Big Data Java Foundation Sixth day job

Source: Internet
Author: User

Tag:java   interface    class inherits    bastract   

First title: Interface buttonlistener{    public void click ();     public void dbclick ();     public void keyup ();     public void keydown ();} Abstract class buttonadapter implements buttonlistener{    public  void dbclick () {        //... Empty implementation     }    public void keyup () {         //... Empty implementation     }    public void keydown () {         //... Empty implementation     }}class myclick extends buttonadapter{    public  void click () {        system.out.println ("My Click event!");     }    public void dbclicK () {        system.out.println ("My double-click event!");     }}class yourclick extends buttonadapter{    public  void click () {        system.out.println ("Your click event!");     }}class Button{    private ButtonListener listener;     public void addlistener (buttonlistener l) {         this.listener = l;    }    public  void click () {        listener.click ();     }    public void dbclick () {         listener.dbclick ();     }}class interfacedemo{    public  static void main (String[] args) {  &NBsp;     myclick myclick = new myclick ();         yourclick yourclick = new yourclick ();         button button = new button ();         button.addlistener (Myclick);         button.click ();         button.dbclick ();         Button.addlistener (Yourclick);         button.click ();     }} The second question: polymorphism is: a kind of things in a variety of forms, a person at the same time is a good father, good husband, good son. property is to save the data, there are the respective objects, when the instantiation of the current object, when the parent property is not covered by the class, when the child class does not change the properties of the parent class can inherit the property. When a method call is present in the stack, a step-by-step search is made, the parent class is requested, and then the subclass is requested, and the method that the subclass requests is the same as the parent class, the method of the father request is overwritten, meaning that the method requested by the parent class has been reset by the method requested by the class. class person{    public string name =  "Person";     public void cry () { &nbsP;      system.out.println ("Person cry ...");     }}class  Man extends Person{    public String name =  "Man";     public void cry () {         System.out.println ("Man cry ...");    }}class women{     Public static void main (String[] args) {        man  man = new man ();         man.cry ();         system.out.println (Man.name);         person p = new man ();         p.cry ();         system.out.println (p.name);     }} The print result is:man  Cry...manman cry...person


This article from "Do Not Tang donation" blog, please be sure to keep this source http://senlinmin.blog.51cto.com/6400386/1771649

Big Data 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.