samples/hellowithsubclassing/src/org/apidesign/hello/ThreeWaysToUseHello.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:58:08 +0200
changeset 153 b5cbb797ec0a
parent 132 3bc4c54f4bcc
child 154 0fd5e9c500b9
permissions -rw-r--r--
up to line 2000
jtulach@70
     1
package org.apidesign.hello;
jtulach@70
     2
jtulach@70
     3
public class ThreeWaysToUseHello {
jtulach@70
     4
jtulach@70
     5
    // BEGIN: hello.say
jtulach@70
     6
    public static void sayHello() {
jtulach@70
     7
        Hello hello = new Hello();
jtulach@70
     8
        hello.hello();
jtulach@70
     9
    }
jtulach@70
    10
    // END: hello.say
jtulach@70
    11
    
jtulach@70
    12
    // BEGIN: hello.subclass
jtulach@70
    13
    private static class MyHello extends Hello {
jtulach@70
    14
        @Override
jtulach@70
    15
        public void hello() { System.out.println ("Hi"); }
jtulach@70
    16
    }
jtulach@70
    17
    // END: hello.subclass
jtulach@70
    18
    
jtulach@70
    19
    // BEGIN: hello.supercall
jtulach@70
    20
    private static class SuperHello extends Hello {
jtulach@70
    21
        @Override
jtulach@153
    22
        public void hello() { super.hello(); System.out.println("Hello once again"); }
jtulach@70
    23
    }
jtulach@70
    24
    // END: hello.supercall
jtulach@70
    25
    
jtulach@70
    26
    /** shows more ways to use a class. prints four various messages */
jtulach@70
    27
    public static void main(String[] args) {
jtulach@70
    28
        sayHello();
jtulach@70
    29
        new MyHello().hello();
jtulach@70
    30
        new SuperHello().hello();
jtulach@70
    31
    }
jtulach@70
    32
}