• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

help needed with inheritance

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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



 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check the spelling of the parameters of your car constructor.
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic