Why is this code not valid? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why is this code not valid?

public class Sololearn { int i = 7; public static void main(String[] args) { i++; } }

7th Aug 2019, 1:45 PM
Samuel
Samuel - avatar
3 Answers
+ 1
to use i in main you have to make it static. public class Sololearn { static int i = 7; public static void main(String[] args) { i++; } }
7th Aug 2019, 2:07 PM
Eze
0
or declare i locally within main or method. public class Sololearn { public static void main(String[] args) { int i=7; i++; } }
7th Aug 2019, 2:12 PM
Eze
0
Nice!
11th Aug 2019, 3:09 PM
Juan Debenedetti
Juan Debenedetti - avatar