author | Jaroslav Tulach <jtulach@netbeans.org> |
Sat, 14 Jun 2008 09:53:25 +0200 | |
changeset 70 | cba5d0a9e9f0 |
child 132 | 3bc4c54f4bcc |
permissions | -rw-r--r-- |
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@70 | 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 |
} |