• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to access class fields within the Main() Method?  RSS feed

 
Terry Conner
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,
How can I get the user to input their values into this program if I can not access them in the Main() method.

 
Anayonkar Shivalkar
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Terry Conner wrote:Guys,
How can I get the user to input their values into this program if I can not access them in the Main() method.


Welcome to CodeRanch!

Please TellTheDetails.

What do you mean by 'this' program? Why can't you access class fields in Main method (do you mean to say 'main' method?)?

Please let us know what exactly are you trying to do and what is the exact problem that you are facing.
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you trying to access anything in the main method? you should write something like thisNow you can see you don’t need access to any variables from the main method. You declare and initialise any fields in the Foo class in the usual fashion, and you may need to pass arguments to its constructor, which I haven’t shown here.

And welcome to the Ranch
 
John McClellan
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kind of related to what somebody said earlier, you might want to do a copy and paste of all your code and put it on here.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John McClellan wrote:Kind of related to what somebody said earlier, you might want to do a copy and paste of all your code and put it on here.


Not necessarily all the code. Just enough to show the problem, with nothing else.

That is, an SSCCE.
 
John McClellan
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason I said all the code was because the program in this case is probably next to nothing in size.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John McClellan wrote:The reason I said all the code was because the program in this case is probably next to nothing in size.


Fair enough.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!