Why is 3 the output of this code?Is it becoz return type of func is void?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why is 3 the output of this code?Is it becoz return type of func is void??

public static void func(int x){ x=8; } public static void main(String[] args){ int x=3; func(x); system.out.println(x); }

23rd Jul 2019, 5:36 AM
Sneha Todurkar
Sneha Todurkar - avatar
2 Answers
+ 2
Yes, as function is not returning any value, updated value of x is not visible outside the function func(). So, the value of x remains 3.
23rd Jul 2019, 5:50 AM
Kuri
Kuri - avatar
0
Thank u:)
23rd Jul 2019, 6:07 AM
Sneha Todurkar
Sneha Todurkar - avatar