Java Reference
In-Depth Information
class. In this manner the superclass constructor is reused and supple-
mented.
When a PartTimer object is built, the fields of the superclass are used for
storing PartTimer data. This is possible even though the fields of Employee
are defined with the private qualifier. However, the data defined in the Em-
ployee class remains encapsulated and is not directly visible to the class
PartTimer.Thus,aPartTimerobjectcannotaccesssomeofitsowndata,ex-
cept by using the methods of the Employee class.
The method printCheck() is polymorphic. In this example, since
printCheck() has the same signature in the superclass and the subclass,
method selection (binding) is based on the object making the call.
Note that this code provides only a stub for the printCheck() methods.
Abstraction and Inheritance
In Java it is possible to have a method that performs no processing opera-
tions, such a method is called an abstract method . The reason for this ap-
parent absurdity is that an abstract method serves to define the signature
thatmustbeusedbyallpolymorphicmethodsinextendedclasses.Thus,an
abstractmethoddefinesaninterfaceinthebaseclass,whileleavingtheim-
plementation to the subclasses.
An abstract class is one that contains one or more abstract methods.
You create an abstract class by including the abstract keyword in the
class declaration statement. For example:
abstract class Dog
{
...
An abstract class cannot be instantiated but it can be extended, that it,
you cannot create an object of an abstract class but other classes can in-
herit from it. Abstract classes can have concrete data and methods, which
perform normally.
Programming with abstract classes
Supposethatyouwerecommissionedtodevelopaprogramforoperatinga
petshopwhichsellsdogs,cats,andbirdstothepublic.Theownerneedsto
identifyeachanimalthatisavailableandkeeptrackofitslocationandsale
price. Specifically, the owner also wants to keep track of each dog and cat
breed,andofthecolorofeachbird.Thereisaplantoaddotherpetspecies
atafuturedate,sothesystemshouldbeeasilyexpandable.Afteranalyzing
the software requirement you propose the following data elements:
Search WWH ::




Custom Search