hello ,
I have tried running your code . It has some minor flaws like placing
of braces { } . After making all the changes i am getting the expected
output as follows :
regular price of car:10000.0
speed of car:240
sale price sedan:0.0
sale price of Ford:-2000.0
sale price of Truck:0.0
Press any key to continue . . .
See the reason you get -2000.0 for sale price of ford is because the
getsaleprice() for Ford class calls super class function
getRegularPrice() but for this Foed object the setRegularPrice() is
not called so the instance variable in class car whish is returned by
the function getRegularPrice() i.e. regularprice retains its default
value which is 0 (zero is by default).
So now the function
public double getSalePrice()
{
return (super.getRegularPrice()-this.getmanufacturerDiscount
());
}
will return something like 0 - 2000 = 2000
and also
for all other values you are getting as zero . You must call the
setter methods for that particular object not just for superclass car
object.
Each object's methods have to be called individually to assign the
instance variables your desired value.
Hope i make sense
Feel free to ask again if u face any problems.
Jasmeet Singh
Java Enthusiast
India
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---