• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

get a value from a void method

 
ahmed mego
Greenhorn
Posts: 6
  • 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
Posts: 3509
16
Android Java
  • 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
Posts: 12186
34
Chrome Java Linux
  • 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: 198
Java Linux Oracle
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic