If I refer non static variable with class name, when one object is there, why it is compile-time error?
I have created one object so one set of non-static variable is there in Heap Area. So if I refer that non-static variable with class name, there is only one non-static variable, so it can use that.
Event if it makes sense, how does the compiler to know that you created only a single instance?
static variables
belongs to theClass
objects (incidentally they are instances of classClass
).