Java Reference
In-Depth Information
The following step enters code to create the abstract class, PasswordException.
To Create an Abstract Class
1. Enter lines 1 through 22 as shown in Figure 10-6. In the comments,
insert your own name as programmer and enter the current date.
TextPad displays code for the initial comments, the abstract class header,
constructors, and the abstract usage() method in the coding window
(Figure 10-7). The keyword, abstract, indicates that the PasswordException
class is an abstract class and that the usage() method is an abstract
method.
abstract keyword
indicates abstract
class
abstract keyword
indicates abstract
method
FIGURE 10-7
As previously discussed, the PasswordException class must be declared as
abstract because it contains an abstract method. Abstract classes are not required
to contain an abstract method; however, if a class does include an abstract
method, the keyword, abstract, must be used to declare the class as abstract and,
thus, prevent instantiation.
The PasswordException class now is completely coded. Remember, this
abstract class does not support a user interface, is not an executable application
or applet, and cannot be used to create objects. Instead, the PasswordException
class is used only for purposes of inheritance — that is, to establish a parent class
for child classes of the PasswordException type.
To build the class file for use with child classes, the code must be saved
and this source file compiled. The steps on the next page save and compile the
PasswordException class source file.
 
Search WWH ::




Custom Search