Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help needed with inheritance

 
Ricky James
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the spelling of the parameters of your car constructor.
 
Kia Phia Ben
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic