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

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

google app engine - 403 Forbidden POST - Flask WTForms -