• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Variable passing between class

 
jo buger
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im trying to pass some variable between classes, but it is not going to let me because of the "actual and formal argument lists differ in length"

say I got this code here





if I pass int spd from blueBike to redBike it should give me an error. So how can I just pass one variable from blueBike to redBike? is that even possible? (redBike is expecting another method to pass to it the gear setting)
 
K. Tsang
Bartender
Posts: 3406
13
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you have 2 methods?

 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jo buger wrote:Im trying to pass some variable between classes, but it is not going to let me because of the "actual and formal argument lists differ in length"

say I got this code here





if I pass int spd from blueBike to redBike it should give me an error. So how can I just pass one variable from blueBike to redBike? is that even possible? (redBike is expecting another method to pass to it the gear setting)



Always follow naming conventions Jo. Class names always start with capital case alphabet. So do the constructor names. So your class and constructor names should be BlueBike and RedBike. If you follow simple steps/rules correctly, most of your mistakes will be eliminated. Get your concepts clear first so that you will think correctly. That is why I said- Read the Kathy-Bates book.

 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And yes, I forgot one major point, WELCOME TO JAVA RANCH!!
 
Winston Gutkowski
Bartender
Pie
Posts: 10273
60
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jo buger wrote:say I got this code here...

First, I think you need to explain what you're trying to do, because I suspect you're overthinking this by a country mile.

So: Given a red bike and a blue bike - which presumably are both subtypes of a Bike (although even that is open to question) - what do you want to do?

Winston
 
Ishan Pandya
Ranch Hand
Posts: 226
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try Variable Arguments concept. I hope it will fulfill the needs..
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote: . . . So: Given a red bike and a blue bike - which presumably are both subtypes of a Bike (although even that is open to question) - . . .
I would certainly question that. I would suggest that colour is an attribute of a bicycle and creating BlueBike or RedBike classes is dubious to say the least.
RacingBike TouringBike TandemBike and MountainBike sound like better types of subclass.
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:
Winston Gutkowski wrote: . . . So: Given a red bike and a blue bike - which presumably are both subtypes of a Bike (although even that is open to question) - . . .
I would certainly question that. I would suggest that colour is an attribute of a bicycle and creating BlueBike or RedBike classes is dubious to say the least.
RacingBike TouringBike TandemBike and MountainBike sound like better types of subclass.


I would have to agree on that as I am an avid cyclist myself. I also have an object of MountainBike and RacingBike each with me at home. (MountainBike.name = "Schwinn" & RacingBike.name = "OrbeaTTG")
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But are they red or blue?
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:But are they red or blue?


Hahahahaha!! LMAO!! Schwinn.color = "blue" and OrbeaTTG.color = "white"
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic