Design Patterns Java™ Workbook

(Michael S) #1
Chapter 20. Introducing Operations

Figure 20.2. The classes Firework and Rocket each have a static method with the same
signature and same return value.


CHALLENGE 20.4


What does the following program print out?

package com.oozinoz.applications;
import com.oozinoz.units.*;
import com.oozinoz.fireworks.*;
public class ShowStatic implements UnitConstants
{
public static void main(String[] args)
{
Length apogee = (Length) METER.times(75);
Firework r = new Rocket("Byebaby", 13.95, apogee);
System.out.println(r.flies());
}
}

In addition to modifiers, return type, and signature, a method header may include a throws
clause. This clause limits some of the exceptions that may occur during the method's
execution.


Exceptions in Methods..............................................................................................................................


A method header may declare that the method throws exceptions. An exception in Java is an
instance of any subclass of Throwable, including the Exception class and the Error
class. Note that the word exception refers to an instance of Throwable but not necessarily to
an instance of Exception. Figure 20.3 shows part of the Throwable hierarchy.

Free download pdf