Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Last edited by amr; December 3rd, 2010 at 08:40 AM.
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)
public class Something{ public static int sum(int a, int b){ return a+b; } } // Something.sum(1,2);//perform the sum
Last edited by copeg; December 2nd, 2010 at 10:08 PM.
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));