samples/hellowithsubclassing/src/org/apidesign/hello/ThreeWaysToUseHello.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Fri, 03 Apr 2020 16:32:36 +0200
changeset 416 9ed8788a1a4e
parent 153 b5cbb797ec0a
permissions -rw-r--r--
Using HTTPS to download the libraries
     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 }