集册 Java实例教程 实现两个接口

实现两个接口

欢马劈雪     最近更新时间:2020-01-02 10:19:05

590
实现两个接口

interface Walkable {

  void walk();
  /*来自 
   nowjava.com*/

}

interface Swimmable {

  void swim();

}


class Turtle implements Walkable, Swimmable{

    private String name;


    public Turtle(String name) {

          this.name = name;

    }


    // Adding a bite() method to the Turtle class

    public void bite() {

        System.out.println(name + " (a turtle) is biting.");

    }

    

    // Implementation for the walk() method of the Walkable interface
    /*
    时 代      J a v a   公   众 号 - nowjava.com
    */

    public void walk() {

        System.out.println(name + " (a turtle) is walking.");

    }


    // Implementation for the swim() method of the Swimmable interface

    public void swim() {

        System.out.println(name + " (a turtle) is swimming.");

    }

}



public class Main {

  public static void main(String[] args) {

    Turtle turti = new Turtle("aa");

    letItBite(turti);

    letItWalk(turti);

    letItSwim(turti);  

  }   

  

  public static void letItBi
展开阅读全文