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
     1 package org.apidesign.hello;
     2 
     3 public class ThreeWaysToUseHello {
     4 
     5     // BEGIN: hello.say
     6     public static void sayHello() {
     7         Hello hello = new Hello();
     8         hello.hello();
     9     }
    10     // END: hello.say
    11     
    12     // BEGIN: hello.subclass
    13     private static class MyHello extends Hello {
    14         @Override
    15         public void hello() { System.out.println ("Hi"); }
    16     }
    17     // END: hello.subclass
    18     
    19     // BEGIN: hello.supercall
    20     private static class SuperHello extends Hello {
    21         @Override
    22         public void hello() { 
    23             super.hello(); 
    24             System.out.println("Hello once again"); 
    25         }
    26     }
    27     // END: hello.supercall
    28     
    29     /** shows more ways to use a class. prints four various messages */
    30     public static void main(String[] args) {
    31         sayHello();
    32         new MyHello().hello();
    33         new SuperHello().hello();
    34     }
    35 }