+ 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); } }

17th Aug 2017, 10:17 AM
Vaibhav Singh Sikarwar
Vaibhav Singh Sikarwar - avatar
4 ответов
17th Aug 2017, 10:37 AM
Gammaburst
Gammaburst - avatar
+ 3
thanks gamma guy for the help
17th Aug 2017, 3:25 PM
Vaibhav Singh Sikarwar
Vaibhav Singh Sikarwar - avatar
+ 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👍👍
17th Aug 2017, 10:35 AM
Gammaburst
Gammaburst - avatar
+ 1
Your welcome Vaibhav😀
17th Aug 2017, 3:33 PM
Gammaburst
Gammaburst - avatar