[Solved] Undefined method why?


Your problem lies here:

   public void main(String args[])
   {
        System.out.println("Set health");
        h = sc.nextInt();
        l(h);  //Root of your problems
   }

method l() is undefined under the scope of class f1. Meaning that f1 do not understand what is l(). To let class f1 know what is it, you can:

   public void main(String args[])
   {
        System.out.println("Set health");
        h = sc.nextInt();

        f2 obj = new f2();  //create an object of class f2
        obj.l(h);  //Now they know l() comes from an f2 object
   }

1

solved Undefined method why?