0
Is it possible to initialize a same variable with same name again and again in different functions...??
3 Respuestas
+ 1
Each variable is tied to the method it is created so yes you could but it may get confusing with large programs seeing the same name in all your methods. Always best to name variables for their specific purpose. Say you need a spare int x in several methods. It would help to name it something like addX for am addition method, SubX for subtraction. Makes it more readable
+ 1
Also, if you need one variable for multiple methods, you could create it as static outside all methods, like underneath the class name. This way, you don't have to keep creating a new variable each time
0
If you read scope of variables it will be helpful