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 }
  • 相关阅读:
    poj2138 Travel Games
    [TJOI2013]松鼠聚会
    [HNOI2013]切糕
    CSS应用
    列表数据显示+分页
    SESSION的应用
    JS中正规表达式的用法以及常用的方法总结
    CSS 定位 (Positioning)
    CSS 边距
    选项卡应用
  • 原文地址:https://www.cnblogs.com/ronle/p/9805698.html
Copyright © 2011-2022 走看看