/*** defines three interfaces, then defines an interface that inherits three interfaces, creates objects *///create white rich beauty three interfaces interface iwhite{ Public void white (); //defines an empty method}interface irich{ public void Rich ();} Interface ibeauti{ public void beauti ();} interface irun{ //Add a new class Public void run ();} Define a iwrb interface inherit three interfaces at a time interface iwrb extends iwhite, irich ,ibeauti{}// Create a womanter implementation of the iwrbclass womanstart implements iwrb { //implementation of three methods public Void white () {System.out.println ("I ' M white");} Public void rich () {System.out.println ("I ' M rich");} Public void beauti () {System.out.println ("I ' M beauti");}} class womanstartrun extends womanstart implements irun{ //implementation by means of inheritance and implementation Expansion Public void run () {System.out.println ("Trot!!!!!!!!!! ");}} Create Local tyrants class Class richman{public void marry (iwrb girl) { //declares a marry method if it meets the criteria ... system.out.println ("Drink a cup of tea!!! ");} public void run (Irun run) {Run.run ();} }//Create a class class richmandemo{public static void Main (string [] args ) { richman m = new richman (); // new a local tyrants womanstart w = new womanstart () ; //new A womanstart m.marry (w); //call marry womanstartrun ru = new womanstartrun ();//new a womanstartrun m.run (RU);}} The advent of interfaces interfaces reduces coupling ---decoupling Adapter : adapters abstract classes. Adapter Mode —————————————————————————————— If there are many methods in the interface, but only one or a few methods are concerned when using the interface (fewer methods of care), If you use conventional means, you need tomethod to be implemented, you can create a type to implement the interface, do not care about the method of empty implementation, the method of care remains unchanged, the definition of the new class inherits the abstract class, the method of interest will be implemented. This mode is called adapter mode, which is commonly used in the processing of button click events in ui design. Polymorphic------------------Define the multiple forms of existence of a: of a certain class of things. for inherited classes, use the parent class type to refer to the object of the child class. for interfaces, you can use interfaces to reference objects created by classes that implement the interface. Benefits and effects The presence of: improves program extensibility and post-serviceability prerequisites: need to exist for inheritance or to implement relationships to have overlay operations inside classes ————— ——————————————————————— defines a class within another class, which is called an inner class (built-in class, nested Class). Access features: internal classes can directly access members in external classes, including private members. while the external class is going to access the members of the inner class, you must establish the inner class of the object inside the class's location inner class definition at the member location can be decorated with private static member modifiers. an inner class that is modified by static can only access static members in an external class. inner class definitions in local locations members in external classes can also be accessed directly. can also access local variables in the local area, but must be final decorated. [Job 1]------------------------------------implement adapter pattern design using abstract classes and interfaces. Involved inThe classes and interfaces are Buttonlistener (interfaces), which contain methods such as Click () / dbclick () / keyup () / keydown (). 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. [Job 2]------------------------------------explain what polymorphism is. Why can functions be overwritten, and properties cannot be overwritten? /*** [job 1]* Define interface functions */// first define four interfaces Interface buttonlistener{void click (); //Click public can omit Void dbclick (); //Double-click void keyup (); // Press the key to release void keydown (); //Push the button}class button{// Button Listener buttonlistener listener ; //means that the Buttonlistener button is a handler for listener //Add Listener Public void addlistener (buttonlistener l) {This.listener = l ;} Impersonation Click event Public void click () {//Handle click event Listener.click ();}} The adapter abstract class buttonlisteneradapter implements buttonlistener{//an empty implementation of the interface public Void dbclick () {}public void keyup () {}public void keydown () {}}//Create a new listener implementation class class Mylistener extends buttonlisteneradapter{public void click () {System.out.println (" Click one ~~~ ! ");}} Class adapterdemo{ public static void main (String[] args) {Button btn = new button (); // Create a new listener Mylistener ml = new mylistener () ; //creates a new class Btn.addlistener (Ml); btn.click ();}} /*** Running Results * c:\users\cc\desktop>java adapterdemo* click one ~~~ !*/[Job 2] explains what polymorphism is. Why can functions be overwritten, and properties cannot be overwritten? A: Definition: A variety of forms of existence of a certain category of things. for inherited classes, use the parent class type to refer to the object of the child class. for interfaces, you can use interfaces to reference objects created by classes that implement the interface. Properties are assets, where the data is accommodated, functions are behaviors, do not hold and store data, soFunctions can be overwritten, and properties cannot.
It 18 Palm Sixth day summary (including jobs)