3 Replies Latest reply: Feb 27, 2007 7:49 AM by 807599 RSS

    non-static method cannot be referenced from static context

    807599
      In the following code I am making a call to method calc. ( I put the service class and the main class in the same file for simplicity ). The code line that says
      result = calc(4);
      is generating an error that says "non-static method calc(double) cannot be referenced from a static context." I don't understand why I am getting this error.
      class Example5 {
      
         int denom = 2;
      
         public static void main(String [] args) {
      
            double result;
            result = calc(4);
            System.out.println(result);
      
         }
      
         public double calc(double num) {
            return (num * num) / denom;
         }
      }