200 Part III: Working with the Big Picture:
Saturday, February 28th, 2009200 Part III: Working with the Big Picture: Object-Oriented Programming Well, you can dig right into the PartTimeEmployeeclass code, make a few changes, and hope for the best. (Not a good idea!) You can follow the previous section s advice and create a subclass of the existing PartTimeEmployeeclass. But wait, you say. The existing PartTimeEmployeeclass already has a findPaymentAmountmethod. Do I need some tricky way of bypassing this existing findPaymentAmountmethod for each double-pay-for-overtime employee? At this point, you can thank your lucky stars that you re doing object- oriented programming in Java. With object-oriented programming, you can create a subclass that overrides the functionality of its parent class. Listing 8-8 has just such a subclass. Listing 8-8: Yet Another Subclass class PartTimeWithOver extends PartTimeEmployee { public double findPaymentAmount(int hours) { if(hours <= 40) { return getHourlyRate() * hours; } else { return getHourlyRate() * 40 + getHourlyRate() * 2 * (hours 40); } } } Figure 8-10 shows the relationship between the code in Listing 8-8 and other pieces of code in this chapter. In particular, PartTimeWithOveris a subclass of a subclass. In object-oriented programming, a chain of this kind is not the least bit unusual. In fact, as subclasses go, this chain is rather short. The PartTimeWithOverclass extends the PartTimeEmployeeclass, but PartTimeWithOverpicks and chooses what it wants to inherit from the PartTimeEmployeeclass. Because PartTimeWithOverhas its own declaration for the findPaymentAmountmethod, the PartTimeWithOverclass does- n t inherit a findPaymentAmountmethod from its parent. (See Figure 8-11.)
If you looking for unlimited one inclusive web hosting plan please check unlimited web hosting website.