jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes help needed with inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "help needed with inheritance" Watch "help needed with inheritance" New topic

help needed with inheritance

Ricky James
Ranch Hand

Joined: Mar 26, 2007
Posts: 83

I have a class called Car and a main class that implements this class. Both are pasted below.

I expect the implementation to print out the price of the car but it is giving me price '0'.

Can anyone please advise as to what I am doing wrong.

Would be extremely thankful.


Joanne Neal

Joined: Aug 05, 2005
Posts: 3742
Check the spelling of the parameters of your car constructor.

Kia Phia Ben
Ranch Hand

Joined: Dec 16, 2005
Posts: 48
Hi Ricky James
I know why result is 0 because in constructor

public Car(int regularPice, int speed, String colour) {
this.regularPrice = regularPrice;
this.colour = colour;
this.speed = speed;
this.regularPrice = regularPrice;
You assign this.regularPrice = regularPrice(value of this not value of parameter)
parameter is name regularPice.
I think regularPice not equal regularPrice and you miss 'r' in name of parameter.
You can tool so that create constructor and getter/setter.
Ricky James
Ranch Hand

Joined: Mar 26, 2007
Posts: 83
Originally posted by Joanne Neal:
Check the spelling of the parameters of your car constructor.


Thanks a lot for the reply Joanne. I think I should go to sleep!

Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3381

It was really a good example to be very careful while going through others code (rather debugging) so that we can find out the silly mistakes like Spelling mistakes which actually causes the bug!!

Thanks for the Posting Ricky James and all others who helped Ricky find out the issue!!

Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: help needed with inheritance
It's not a secret anymore!