Basic use of the Java interface

Source: Internet
Author: User

<span style= "font-family:arial, Helvetica, Sans-serif; Background-color:rgb (255, 255, 255); " > Interface Use my main is the code of the dispersion characteristics, but the basis of the dispersion is several, that is, the so-called "high cohesion, low coupling" features, from the point of view of code maintenance, get Oh great improvement, below is a small section of my typical interface using instance code:</span>
<span style= "font-family:arial, Helvetica, Sans-serif; Background-color:rgb (255, 255, 255); " ></span><pre name= "code" class= "java" >package com_5;interface computer{public Void Open ();p ublic void Close ();} public class Inter {/** * @param args */public static void main (string[] args) {S1 P1 = new S1 ();p 1.open (); s2 p2 = new S2 ( );p 2.close ();}} Class S1 implements Computer{public Void Open () {System.out.println ("S1 computer Boot");} public void Close () {System.out.println ("S1 computer shuts Down");}} Class S2 implements computer{public void Close () {System.out.println ("S2 computer Off");} public void Open () {System.out.println ("S2 computer");}}


Interfaces do not require entities, but as long as the interface is connected, it is necessary to complete the interface method, which is the main feature of the interface.

Second, interfaces cannot be inherited.

Basic use of the Java 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.