File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

get a value from a void method

 
ahmed mego
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I get the variable "n" in the void method:
i know that void return null but there are any solution for that

I want to get the value of "n" to use it in this method:
 
K. Tsang
Bartender
Pie
Posts: 3222
12
Android Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are both methods in the same class? If so, can this variable become an instance variable?
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12017
24
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As written, you can't. the variable n doesn't exist once you leave the method.

so, you can either:

a) change the method to actually return a value
b) make n a class variable that gets set inside the method
c) make the call to get the value where you need it and can use it.

quite frankly, the method NoOfProcess, as written, is basically worthless.
 
Manoj Kumar Jain
Ranch Hand
Posts: 195
Java Linux Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ahmed mego wrote:How can I get the variable "n" in the void method:
i know that void return null but there are any solution for that


void method can't even returns null. It returns nothing.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic