I keep having problem on trying to call the method 'in3050'.Please someone guide me on this????

public class NumberCheck {

    private static void main(String[] args) {
        int num1 = 31;
    int num2 = 40;
    boolean check = in3050(num1,num2);

      public boolean in3050(int a, int b) {
  if (a >= 30 && a <= 40 && b >= 30 && b <= 40)
     return true;
  else if (a >= 40 && a <= 50 && b >= 40 && b <= 50)
     return true;
     return false;


main is a static method - it runs without any instance of NumberCheck.
But in3050 is an instance method, so it needs an instance of NumberCheck to run.
You can either
make in3050 static (quick fix, but heading in the wrong direction for understanding object oriented proramming)
in main, create a new instance of NumberCheck, and use that to call in3050 (whic is how things usually go in an object oriented program)

ps: next time you post a problem, include a complete copy of the compiler or runtime error message(s) so we don't have to guess what the problem is.

Edited 3 Years Ago by JamesCherrill

can u please explain what is the error specified by the interpreter? So it will be easy for us to clarify it.

ss125: the answer has already been given. (s)he's trying to call an instance method in a static context, which can not be done.

^ ... or creating an instance with which to call it. (Just making everything static means you have more to un-learn as you progress through Java programming)

Hi all,

Thanks for explaning to me on my error.Still did not manage to understand fully what you guys trying to say.However,i will based on what you guys had said and read up on the basics of Java. Thanks Alot.

This question has already been answered. Start a new discussion instead.