+ 6
Why this is happening
class A{int a;} main(){ A b=new A(); b.a++; } //no errors but when I do that main(){ int x; x++; //error } maybe because of the type of variable the first is global and the second is local
2 Respuestas
+ 2
In the second one you haven't initialized the local variable, so you can't do any operations on it.
In the first one, class level variables are initialized to their default values when you create a new object, so the int in the class A initializes to 0
+ 3
Please refer:
https://www.sololearn.com/Discuss/1493224/?ref=app