I have a doubt please clear it....in java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

16th May 2020, 10:15 AM
Yogeshwaran
1 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);
16th May 2020, 11:00 AM
Avinesh
Avinesh - avatar