+ 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; }

15th Mar 2020, 3:47 PM
Alex Schmidt
Alex Schmidt - avatar
4 ответов
+ 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
15th Mar 2020, 3:52 PM
A͢J
A͢J - avatar
+ 6
Yes
15th Mar 2020, 3:52 PM
Cmurio
Cmurio - avatar
+ 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.
15th Mar 2020, 3:55 PM
Jayakrishna 🇮🇳
+ 2
Thanks for all your help
15th Mar 2020, 3:58 PM
Alex Schmidt
Alex Schmidt - avatar