Answer:
To make your program work, either you need to declare the instance variables static or, we should refer them using an object in the method you should try like this:
public class StaticDemo {
int i = 0;
public static void main(String[] args) {
System.out.println("in main method which is static");
StaticDemo obj = new StaticDemo();
obj.i = 5;
obj.instanceMethod();
}
public void instanceMethod(){
System.out.println("Value of i- " + i);
}
}