Results 1 to 4 of 4
- 02-11-2011, 02:00 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 4
- Rep Power
- 0
How can you use a variable in a method that is declared in main?
I'm trying to write a program in which i have several methods. I inputted an array of strings in main and want to use this array in both main and the methods. How do I go about doing this? I need to declare the variable in the method, but I need the original array to be the value of this.
Thanks
- 02-11-2011, 02:17 AM #2
The OO approach would be to create a class and declare your data as one or more instance variables. That way all methods will have access to them.
If this is beyond your scope then you will have to pass your data as parameters.
- 02-11-2011, 02:32 AM #3
Member
- Join Date
- Feb 2011
- Posts
- 4
- Rep Power
- 0
thank you so much.
Last edited by drhinri; 02-11-2011 at 02:41 AM.
- 02-11-2011, 02:40 AM #4
Member
- Join Date
- Feb 2011
- Posts
- 24
- Rep Power
- 0
Similar Threads
-
Calling The main method from another method
By SwissR in forum New To JavaReplies: 3Last Post: 07-27-2010, 11:03 AM -
local variable tf1 is accessed from within inner class; needs to be declared final
By shoeb83 in forum New To JavaReplies: 2Last Post: 12-05-2009, 11:24 AM -
calling method from main method
By bob_bee in forum New To JavaReplies: 4Last Post: 10-02-2009, 05:30 PM -
[SOLVED] Why main() in java is declared as public static void main?
By piyu.sha in forum New To JavaReplies: 5Last Post: 10-06-2008, 12:11 AM -
Calling a variable from main to another class
By itsme in forum New To JavaReplies: 1Last Post: 12-18-2007, 03:35 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks