• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to best get value of int variable into another method?

 
Noam Ingalls
Ranch Hand
Posts: 60
Chrome Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've got an int that I need to pass into another class's method; what's the best way for me to do that? Declare the int as static? Although it wouldn't help right? Make it a separate method? Or try and use setters and getters which I don't really understand?

The int is keeping track of how many lines have been processed; I set up a loop to read the lines in the array myString, and used a variable called lineCounter to keep track in the method parseCommands in the main. Now I need the value of lineCounter to be passed into this class EndStatement; not sure how to get it in there though. Can someone help, or link to an example that shows how? Thanks!



Class I need to get the variable into:




 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could pass it as a parameter
 
Noam Ingalls
Ranch Hand
Posts: 60
Chrome Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right, got it... problem fixed. Thanks.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic