17, the combination of multi-state technology and interface

Source: Internet
Author: User

 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

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.