PackageCom.lei.duixiang;/*** 1, the combination of polymorphic technology and interface * 2, any field defined in the interface is automatically static and final * 3, the method defined in the interface must be declared as public or abstract, even if the method is not declared as public , it is also public * *@authorAdministrator **/Interfacedrawtest {//Defining Interfaces Public voiddraw ();}//defines the parallelogram class, which inherits the Quadrilateral class and implements the Drawtest objectclassParallelogramgleuseinterfaceextendsQuadrangleuseinterfaceImplementsDrawtest { Public voidDraw () {//because the class implements the interface, the draw () method needs to be overriddenSystem.out.println ("parallelogram. Draw ()"); } voidDoanything () {//overriding the parent class method//Note that there is no public modifier before the method }}//defines a square class that inherits the Quadrilateral class and implements the Drawtest objectclassSquareuseinterfaceextendsQuadrangleuseinterfaceImplementsDrawtest { Public voidDraw () {//TODO auto-generated Method StubSystem.out.println ("square. Draw ()"); } voiddoanything () {//Note that there is no public modifier before the method }} Public classQuadrangleuseinterface {//Defining quadrilateral Classes voidDoanything () {//Note that there is no public modifier before the method//somesentence } Public Static voidMain (string[] args) {//interface can also be used for up-conversion operationsDrawtest[] D = {Newsquareuseinterface (),Newparallelogramgleuseinterface ()}; for(inti = 0; i < d.length; i++) {D[i].draw (); } }}
17, the combination of multi-state technology and interface