The code is clear.
Write a base class fatherclass. Java
package com;public class FatherClass {public void speak(){System.out.println("Father method,speak() ");}public void sing(){System.out.println("Father method,sing() ");}public void jump(){System.out.println("Father method,jump() ");}public void run(){System.out.println("Father method,run() ");}}
Write an interface motherinterface. Java
package com;public interface MotherInterface {public void cook();public void clean();public void love();}
Write a specific class sonclass. Java
Package com; public class sonclass extends fatherclass implements motherinterface {@ overridepublic void Cook () {// todo auto-generated method stubsystem. out. println ("Son method Cook ()") ;}@ overridepublic void clean () {// todo auto-generated method stubsystem. out. println ("Son method clean ()") ;}@ overridepublic void love () {// todo auto-generated method stubsystem. out. println ("Son method love ()");}////// /////////// Overload base class method ////////////////////// /// // public void jump () {system. out. println ("Son method, jump (), extends fatherclass");} public void run () {system. out. println ("Son method, run (), extends fatherclass ");} /// // write your own method //////////////// //// // public void mymehtodd () {system. out. println ("Son method, mymehtodd (), my own method");} public static void main (string [] ss) {// use a base class instance object, object only There are base class methods // (if the base class method is reloaded, the overload method is used) fatherclass fc = new sonclass (); // interface instance object, the object only has interface methods // These methods must implement motherinterface MI = new sonclass (); // use this class instance object, there are both base class methods (there are overload methods that take the heavy load ); // There are also interface methods (interface methods must be implemented), and their own unique methods of this class. Sonclass son = new sonclass (); system. out. println ("-------- base class instance object FC ------------"); FC. speak (); FC. sing (); FC. jump (); FC. run (); system. out. println ("-------- interface instance object mi ------------"); Mi. cook (); Mi. clean (); Mi. love (); system. out. println ("-------- the object son ------------"); son. speak (); son. sing (); son. jump (); son. run (); son. cook (); son. clean (); son. love (); son. mymehtodd ();}}
Console printing:
-------- Base class instance object FC ------------
Father method, speak ()
Father method, sing ()
Son method, jump (), extends fatherclass
Son method, run (), extends fatherclass
-------- Interface instance object mi ------------
Son method Cook ()
Son method clean ()
Son method love ()
-------- Son ------------ object of this class instance ------------
Father method, speak ()
Father method, sing ()
Son method, jump (), extends fatherclass
Son method, run (), extends fatherclass
Son method Cook ()
Son method clean ()
Son method love ()
Son method, mymehtodd (), my own Method