Using local declared variables in a different method in Java

后端 未结 3 1410
后悔当初
后悔当初 2021-01-25 18:49

I am having a little difficulty with a school assignment, long story short I declared two local variables in a method and I need to access those variables outside the method : <

3条回答
  •  鱼传尺愫
    2021-01-25 19:09

    You can't access local variables from method A in method B. That's why they are local. Take a look: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/variables.html

    As such, local variables are only visible to the methods in which they are declared; they are not accessible from the rest of the class.

    I recommend to use solution written by @MadProgrammer - create class which contains feet and inches.

提交回复
热议问题