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