hello,
please tell me how to use the below stated method " Amr(x , y) " in anoth/different .java file.
Printable View
I suggest you read the following tutorial to help you learn to do this: Classes (The Java Tutorials). As is, you can a) call a static method from the main, b) create a new object and call a method of said object, c) do the math in main accessing the values of a created object d) its probable I missed another way. For example, a)
Code :public class Something{ public static int sum(int a, int b){ return a+b; } } // Something.sum(1,2);//perform the sum
Two ways.
One, make it a static method and do this in the main method
System.out.println(className.Amr(2,3));
Or use the constructor of your first class to make an object of that class then
System.out.println(object.Amr(2,3));