Page 526 - Introduction to Programming with Java: A Problem Solving Approach
P. 526
492 Chapter 12 Aggregation, Composition, and Inheritance
instance variables and methods. Figure 12.14’s diagram also includes a Person class. Our previ- ous Manager and SalesPerson classes now inherit a variable, two constructors and a method from this Person class. The inheritance reduces the Manager and SalesPerson classes to the simpler Manager2 and SalesPerson2 classes. These simpler classes do not need explicit declaration of name and explicit definition of getName because they inherit these members from Person. Read through the code for the shortened Manager2 and SalesPerson2 classes in Figures 12.15 and 12.16.
/********************************************
*
Manager2.java
Dean & Dean
This represents car dealership manager
********************************************/
*
*
*
public class Manager2 extends Person
{
}
public Manager2(String name)
{
}
super(name);
// end Manager2 class
Figure 12.15
Manager2 class for Dealership2 program
Apago PDF Enhancer
/***********************************************
*
SalesPerson2.java
Dean & Dean
This represents car sales person
***********************************************/
*
*
*
public class SalesPerson2 extends Person
{
}
// end SalesPerson2 class
private double sales = 0; // sales to date
//********************************************
public SalesPerson2(String name)
{
}
super(name);
Figure 12.16
SalesPerson2 class for Dealership2 program
The Car class is unchanged from the original Dealership program; if you want to see its code, look back at Figure 12.4. The Dealership2 and Dealership2Driver classes are the same as the