• Post Reply Bookmark Topic Watch Topic
  • New Topic

how can i use the variable of a method in another method of the same class  RSS feed

 
adebari olalekan
Ranch Hand
Posts: 61
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to use a variable created in a method,  in another method of the same class, how do i do it



i want to use the of the sodo() method, but all i get is ,
todo can not be resolved to a variable
. i know i am doing it wrongly , because i have seen people make such calls and it worked; so if someone could shed light
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Variables declared in a method, are local variables, and are not in scope outside of the method. In other words, you can't use the variable. You can, however, pass the value out of the method -- either by using a non-local variable, or via returning it from the method.

Henry
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!