Two Laptop Bag*
The moose likes Beginning Java and the fly likes Variable passing between class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Variable passing between class" Watch "Variable passing between class" New topic
Author

Variable passing between class

jo buger
Greenhorn

Joined: Feb 16, 2013
Posts: 2
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

Joined: Sep 13, 2007
Posts: 2233
    
    7

Why don't you have 2 methods?



K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

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.


~ Mansukh
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

And yes, I forgot one major point, WELCOME TO JAVA RANCH!!
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7529
    
  18

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

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Ishan Pandya
Ranch Hand

Joined: Feb 06, 2012
Posts: 219

Try Variable Arguments concept. I hope it will fulfill the needs..


OCPJP
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37958
    
  22
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

Joined: Jul 27, 2010
Posts: 1157

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

Joined: Oct 13, 2005
Posts: 37958
    
  22
But are they red or blue?
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

Campbell Ritchie wrote:But are they red or blue?


Hahahahaha!! LMAO!! Schwinn.color = "blue" and OrbeaTTG.color = "white"
 
wood burning stoves
 
subject: Variable passing between class
 
Similar Threads
Encapsulation and getter&setter methods
Threading
Error when using package
Initializing Instance Members
It compiled but couldn't run,help me make it run