New course! Every coder should learn Generative AI!
Try a free lesson0
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); }
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.
0
Thank u:)