• Register
Welcome to Kodlogs, programming questions and answer website.
0 votes
10 views

Problem :

Getting bellow error
"non static method cannot be referenced from a static context java"
by (6.9k points)  

1 Answer

0 votes

Solution :

One can not make the reference to a Static variable from a NonStatic method. 

Static Variables are called class variables as they belong to the class and they have only one instance which is created at the begining only. 
NonStatic Variables need to be initialized every time one creates an object of that Class.

When one uses new() keyword to create a copy of every NonStatic filed for every object, but it is not the case for Static variables. 
So it gives compile time error if you are refering a Static variable from a NonStatic method.
by (20.3k points)  
...