Your method does nothing.
Yes, it adds the two numbers together, and puts the result in a variable called "sum1".
But then, the method ends. Since "sum1" is a local variable, it is thrown away when the method exits.
If you want to preserve the result for later use, there are only three practical ways:
1) Return the result as a datatype - I know, you don't want to, but it is the most sensible way to do it:
public static double sum (double a,double b)
{
return a + b;
}
2) Return the result as a static variable (since your method is static, you can't return it as a class variable)
private static double result;
public static double sum (double a,double b)
{
result = a + b;
}
This has the disadvantage that if you have two instances of your class, they will both overwrite the same variable.
3) Change your method to a non-static method, and return the result via a class level variable:
private double result;
public double sum (double a,double b)
{
result = a + b;
}
This is a clumsy solution, particularly if there are many routines doing this for different purposes - each needs it's own variable.
Use option (1) - it is the easiest, most flexible, and most friendly!