Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (10.2k points)

The very common beginner mistake is when you try to use a class property "statically" without making an instance of that class. It leaves you with the mentioned error message:

You can either make the non-static method static or make an instance of that class to use its properties.

Why? I am not asking for solutions. I would be grateful to know what is the reason behind it. The very core reason!

private java.util.List<String> someMethod(){

    /* Some Code */

    return someList;            

}

public static void main(String[] strArgs){          

     // The following statement causes the error. You know why..

    java.util.List<String> someList = someMethod();         

}

1 Answer

0 votes
by (46k points)
You can't call something that doesn't subsist. Since you haven't designed an object, the non-static method doesn't exist yet. A static method (by definition) always exists.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...