samples/hellowithsubclassing/src/org/apidesign/hello/ThreeWaysToUseHello.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:56:12 +0200
changeset 132 3bc4c54f4bcc
parent 70 cba5d0a9e9f0
child 153 b5cbb797ec0a
permissions -rw-r--r--
Truncating all examples to 80 characters per line
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@132
    22
        public void hello() { 
jtulach@132
    23
            super.hello(); 
jtulach@132
    24
            System.out.println("Hello once again"); 
jtulach@132
    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
}