annotate paper/src/java-interface-implements.java @ 131:988b3024d685

update
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Mon, 08 Feb 2021 05:49:37 +0900
parents 3a8c21a37bf1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
56
3a8c21a37bf1 interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 // interface
3a8c21a37bf1 interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 interface Animal {
3a8c21a37bf1 interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 public void animalSound(); // interface method (does not have a body)
3a8c21a37bf1 interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 public void sleep(); // interface method (does not have a body)
3a8c21a37bf1 interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 }
3a8c21a37bf1 interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
3a8c21a37bf1 interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 // Pig "implements" the Animal interface
3a8c21a37bf1 interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 class Pig implements Animal {
3a8c21a37bf1 interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 public void animalSound() {
3a8c21a37bf1 interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 // The body of animalSound() is provided here
3a8c21a37bf1 interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 System.out.println("The pig says: wee wee");
3a8c21a37bf1 interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 }
3a8c21a37bf1 interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 public void sleep() {
3a8c21a37bf1 interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 // The body of sleep() is provided here
3a8c21a37bf1 interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 System.out.println("Zzz");
3a8c21a37bf1 interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 }
3a8c21a37bf1 interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 }