+ 4
Plzz anyone tell me what is the error in this java program I am trying to create a method for multiplication ?
public class My { int multiply (int x, int y) { return x*y; } } public class Program { public static void main(String [] args) { int k = multiply(4,9); System.out.println(k); } }
4 ответов
+ 2
https://code.sololearn.com/cUnxeKQk3q8Z/?ref=app
See now it runs!
+ 3
thanks gamma guy for the help
+ 2
Hi Vaibhav, I found the flaw!
First write "static" before "int". So that you can access this method in other class without creating an object.
Second, write "My." (with that dot at the end) to tell the compiler where to find the method "multiply".
Rest is OK👍👍
+ 1
Your welcome Vaibhav😀