java - Why is a non-static variable not able to be referenced from a static context? -
i wondering if there reason why object cannot performed non-static variable? able fix error, (obviously) wondering why.
static variable initialized when class loaded jvm
on other hand instance variable has different value each instances , created when instance of object created either using new()
operator or using reflection class.newinstance()
.
so if try access non static variable without instance compiler complain because variables not yet created , don't have existence until instance created , associated instance. in opinion reason make sense disallow non static or instance variable inside static context non existence of instance.
read more here
Comments
Post a Comment