samples/hellowithsubclassing/src/org/apidesign/hello/ThreeWaysToUseHello.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:58:11 +0200
changeset 154 0fd5e9c500b9
parent 153 b5cbb797ec0a
permissions -rw-r--r--
Merge: Geertjan's changs up to 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@154
    22
        public void hello() { 
jtulach@154
    23
            super.hello(); 
jtulach@154
    24
            System.out.println("Hello once again"); 
jtulach@154
    25
        }
jtulach@70
    26
    }
jtulach@70
    27
    // END: hello.supercall
jtulach@70
    28
    
jtulach@70
    29
    /** shows more ways to use a class. prints four various messages */
jtulach@70
    30
    public static void main(String[] args) {
jtulach@70
    31
        sayHello();
jtulach@70
    32
        new MyHello().hello();
jtulach@70
    33
        new SuperHello().hello();
jtulach@70
    34
    }
jtulach@70
    35
}