Thanks for the suggestions. Brenden, your suggestion about using super.getSalePrice() makes sense. The only issue I have is that since Ford class is a subclass of Car class, the super.getSalePrice() will return 0. Which is probably not what is intended (despite the current state og the Big 3 :) ). I still think that Ford is meant to be a sub-class of Truck class and not Car class.
Any other comments? Thanks Raja On Feb 17, 5:31 pm, [email protected] wrote: > Raja,The way I approached the Ford manufacturerDiscount was to turn it into a > percentage rather than a fixed value (as that's what the other examples used > and the assignment was ambiguous).pxk,Calling the super getSalePrice method > allows us to take advantage of the existing code and augment it with the > additional steps we need, so it's good re-use. Also, the this reference would > could cause problems like getting into an endless loop (depending upon logic > in the method)[email protected] by: > [email protected] > > 18/02/2009 05:46 AMPlease respond to > [email protected] Java Programming Online Training Course By Sang Shin > <[email protected]>ccSubject[java programming] Re: > Homework Exercise LAB-1023 > Why don't you try it with this.getSalePrice() instead of > super.getSalePrice()? > On Feb 17, 2:24 pm, Raja Krishnamoorthy <[email protected]> wrote: > > Hi, I have a question on the Homework Exercise: > > one of the points says: > > > > - Create a subclass of Car class and name it as Ford. The Ford class has > > the following fields and methods > > - int year; > > - int manufacturerDiscount; > > - double getSalePrice(); // From the sale price computed from Car > > class, subtract the manufacturerDiscount. > > > > The problem that I see with this exercise is that if Ford is a sub-class of > > Car, then we over0ride the method getSalePrice() in the Car class. > > Since Car is the super class, this method may return 0, since it can be > > overridden. > > So in the Ford sub class if I code the method as follows: > > public double getSalePrice(){ > > return super.getSalePrice() - manufacturerDiscount; > > } > > > > Then I will get a negative value for price. > > > > Should Ford be a sub-class of Truck class? > > > > Thanks > > > > RajaThis email is sent by Australian Insurance Holdings Pty Ltd or a > > related body corporate (AIH) and is for the intended addressee. The views > > expressed in this email and attachments (email) reflect the views of the > > stated author but may not reflect views of AIH. This email is confidential > > and subject to copyright. It may be privileged. If you are not the intended > > addressee, confidentiality and privilege have not been waived and any use, > > interference with, or disclosure of this email is unauthorised. If you are > > not the intended addressee please immediately notify the sender and then > > delete the email. AIH does not warrant that this email is error or virus > > free. --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/javaprogrammingwithpassion?hl=en -~----------~----~----~----~------~----~------~--~---
