+ 1
Can we assign a non-static variable to a static method?
If that is the declaration of x... int x = sum(2, 4); And that is the declaration of sum... public static int sum(int x, int y){ return x + y; }
4 Answers
+ 7
Alex Schmidt This is challenge question. I also got the same issue. Answer was, it will give error.
We can assign. Check here I didn't get any problem.
https://code.sololearn.com/cxAqYNk0haeK/?ref=app
+ 6
Yes
+ 2
It not assigning non-static variable to static method..
It is calling sum function and assigning or storing returned result to Integer variable.
Yes. You can but you can call sum(2,3) in another static method only..
You can't call static sum method from non - static method.
+ 2
Thanks for all your help