I have a doubt please clear it....in java | SoloLearn: Learn to code for FREE!

+1

I have a doubt please clear it....in java

I want to access a variable . --------------------------------------------------------------------- for eg int a = 34 data type in a user defined method inp() (return type method) from a main(String [] args) method. --------------------------------------------------------------------- But I don't know how to access it --------------------------------------------------------------------- Please note that both inp() method and main(String[] args) method are located in same class For better understanding my question please see this code https://code.sololearn.com/cF2eii2R2XZa/?ref=app

5/16/2020 10:15:51 AM

Yogeshwaran

1 Answer

New Answer

+1

Hi Yogeshwaran any variable declared inside a method has a local scope and can be accessed only within the method but you can always return it. You can write just this in main()- int x = inp(); System.out.println(x);