aspose file tools*
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "help needed with inheritance" Watch "help needed with inheritance" New topic
Author

help needed with inheritance

Ricky James
Ranch Hand

Joined: Mar 26, 2007
Posts: 83
Hello,

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.

Ricky



Joanne Neal
Rancher

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


Joanne
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!

Cheers
Ricky
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

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 agree. Here's the link: http://aspose.com/file-tools
 
subject: help needed with inheritance