August 2004
Intermediate to advanced
480 pages
9h 41m
English
A common question regarding abstract classes is how to use exceptions with their method declarations. What exceptions can an inheriting method throw with respect to the inherited method? Consider the following class, whose single method throws one exception: IOException.
public abstract class AbstractPrinter {
abstract void printMessage(String msg) throws IOException;
}
The implementation of this abstract class is shown in PrinterImp1.java. To implement an abstract class, you simply extend it, just as you would extend any other class, using the extends keyword.
package net.javagarage.demo.abstractclasses; import java.io.IOException; public class PrinterImpl extends AbstractPrinter { void ...Read now
Unlock full access