/** * @author mh, inspired by Mark Lutton, Brookline, NH * @version 1.0 * @date 13.01.2003 * @package informatik2.hello * @class Hello8 */ // interface realization by an abstract class // consisting only of abstract methods public class Hello8 { public static void main (String[] argv) { Mouth mouth = new SimpleMouth("Hello, World!"); mouth.say(); mouth.open("Hello, Europe!"); mouth.say(); Mouth mund = new CountingMouth(); mund.open("Hallo, Welt!"); mund.say(); mund.open("Hallo, Europa!"); mund.say(); } // main } // Hello6 //--------------------- cut into separate files ----------------------------- abstract class Mouth { abstract void say(); abstract void open(String thought); } // Mouth //--------------------- cut into separate files ----------------------------- class SimpleMouth extends Mouth { public SimpleMouth() { what = null; } // SimpleMouth public SimpleMouth (String thought) { what = thought; } // SimpleMouth public void say() { System.out.println(what); } // say public void open (String thought) { what = thought; } // open private String what; } // SimpleMouth //--------------------- cut into separate files ----------------------------- class CountingMouth extends Mouth { public CountingMouth () { what = null; count = 0; } // CountingMouth public CountingMouth (String thought) { what = thought; count = 0; } // CountingMouth public void say() { count++; System.out.println("(" + count + ") " + what); } // say public void open (String thought) { what = thought; } // open private String what; private int count; } // CountingMouth