You access non static variable inside static method or block by creating an instance of class
and using that instance to reference instance variable.
public class Test { private int count=0; public static void main(String args[]) throws IOException { StaticTest test = new StaticTest(); //accessing static variable by creating an instance of class test.count++; } }
0 comments:
Post a Comment