Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Data Science
  3. Question
Data Science

non-static variable cannot be referenced from a static context

Asked by Kaalappan Shingh Jul 12, 2021 1.5K views 1 answer
Share

About this question

Here is the code

class method
{
    int counter = 0;
    public static void main(String[] args)
    {
        System.out.println(counter);
    }
}
It gave me this error.

Main.java:6: error: non-static variable counter cannot be referenced from a static context

        System.out.println(counter);

                           ^

How do I make it recognize the variables of the class?


Your answer

1 Answer

More Data Science discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Data Science Blogs

Guides, tips and career advice on Data Science from JanBask experts.