b is not a static variable while a is thats why you are getting that error
\
Try decalring b in main and see the differnce
Yes vishal I understand that , if declared in main it will behave as a local variable , but
I just wanted to understand
why we cant assign the nonstatic variable a static value , rather than remembering it .
I assume its just a part of java , maybe there is no logic.
Pratik D mehta wrote:so there is no logic behind - that you cannot give a static variable value to the instance variable directly .
Of course there's logic behind it--there's no instance variable available to assign a value to.Short version: You have to have an instance before you can access an instance's properties.