samples/hellowithsubclassing/src/org/apidesign/hello/ThreeWaysToUseHello.java
changeset 70 cba5d0a9e9f0
child 132 3bc4c54f4bcc
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/samples/hellowithsubclassing/src/org/apidesign/hello/ThreeWaysToUseHello.java	Sat Jun 14 09:53:25 2008 +0200
     1.3 @@ -0,0 +1,32 @@
     1.4 +package org.apidesign.hello;
     1.5 +
     1.6 +public class ThreeWaysToUseHello {
     1.7 +
     1.8 +    // BEGIN: hello.say
     1.9 +    public static void sayHello() {
    1.10 +        Hello hello = new Hello();
    1.11 +        hello.hello();
    1.12 +    }
    1.13 +    // END: hello.say
    1.14 +    
    1.15 +    // BEGIN: hello.subclass
    1.16 +    private static class MyHello extends Hello {
    1.17 +        @Override
    1.18 +        public void hello() { System.out.println ("Hi"); }
    1.19 +    }
    1.20 +    // END: hello.subclass
    1.21 +    
    1.22 +    // BEGIN: hello.supercall
    1.23 +    private static class SuperHello extends Hello {
    1.24 +        @Override
    1.25 +        public void hello() { super.hello(); System.out.println("Hello once again"); }
    1.26 +    }
    1.27 +    // END: hello.supercall
    1.28 +    
    1.29 +    /** shows more ways to use a class. prints four various messages */
    1.30 +    public static void main(String[] args) {
    1.31 +        sayHello();
    1.32 +        new MyHello().hello();
    1.33 +        new SuperHello().hello();
    1.34 +    }
    1.35 +}