When I use the this keyword for accessing a non-static variable in a class, Java doesn\'t give any error. But when I don\'t use it, Java gives an error. Why mus
this
Please look at the Java Language Specification: https://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.3.2.3
This is the reason, IMO: The usage is via a simple name.
The usage is via a simple name.
So in this case you have to specify the name using this.