Post
Java
While I’m working on a Java program, I got this compiler error: non-static variable count can not be referenced from a static context. Can anyone tell me What does it mean, why this error occurs, and How to fix this error?
Posted on 6th December 2023
Hey Kusum,
The non-static variable cannot be referenced from a static context is compiler error that occurs when the user tries to put program code to access a non-static variable inside main in Java that is static.
public class Static Test{
Private int count=0;
public static void main(String args[]) throws IOException{
count++; //compiler error: non-static variable count cannot be referenced from a static context
}
}
STILL GOT QUERIES?
Copyright © 2013 - 2023 MindMajix Technologies