Hi

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

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)
  {
     System.out.println("LOL");
     return true;
  }
  else if (a >= 40 && a <= 50 && b >= 40 && b <= 50)
  {
     return true;
  }
  else
  {
     return false;
  }
    }

}

you must either declare that method as static, or call it through an instance of NumberCheck.

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)
or
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.

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.

That's right. You can't do that without a static method. Not in this case.

^ ... 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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.