zoukankan      html  css  js  c++  java
  • JAVA的接口

    用法:

     1 interface A {
     2     public static final int i = 10;
     3 
     4     public void runLoad();
     5 }
     6 
     7 public class Demo implements A {
     8     // 实现接口中的方法
     9     @Override
    10     public void runLoad() {
    11         System.out.println("这是调用的接口中的方法");
    12     }
    13 
    14     public static void main(String[] args) {
    15         Demo d = new Demo();
    16         d.runLoad();
    17     }
    18 }

    示例:

     1 //铅笔
     2 class Pencil {
     3     String name;
     4 
     5     public Pencil(String name) {
     6         this.name = name;
     7     }
     8 
     9     public void writer() {
    10         System.out.println(name + "写字");
    11     }
    12 }
    13 
    14 //橡皮檫接口
    15 interface Eraser {
    16     public void remove();
    17 }
    18 
    19 //带橡皮檫的铅笔
    20 class PencilEraser extends Pencil implements Eraser {
    21     public PencilEraser(String name) {
    22         super(name);
    23     }
    24 
    25     @Override
    26     public void remove() {
    27         System.out.println(name + "涂改");
    28     }
    29 }
    30 
    31 public class DemoPencil {
    32     public static void main(String[] args) {
    33         PencilEraser p = new PencilEraser("2B铅笔");
    34         p.writer();
    35         p.remove();
    36     }
    37 }
  • 相关阅读:
    Explain执行计划
    SQL优化(SQL + 索引)
    SQL(含索引)
    分组聚合 merger
    服务分组 group
    多注册中心 registry
    多协议 protocol
    常用协议 —— webservice://
    常用协议 —— http://
    最强AngularJS资源合集
  • 原文地址:https://www.cnblogs.com/ronle/p/9805698.html
Copyright © 2011-2022 走看看