The method "public static void main(String[] args)" is static and the method "public public int ad(int a, int b)" is non-static.
If you want to reach the method "public int ad(int a, int b)" then make an instance of class Sum and call the method "ad(int a, int b)", or make the method "ad(int a, int b)" static. As already mentioned in comments above, "public static void main(String[] args)" has no return type - it is void, so no "return int ad()" in main method is needed.
Alrernative 1 - Make an instance of class Sum and call method ad(int a, int b):
public class Sum {
int a;
int b;
int add;
public int ad(int a, int b) {
int add = (int) a + b;
return add;
}
public static void main(String[] args) {
Sum sum = new Sum(); // Make an instance of class Sum
int result = sum.ad(1, 2); // and call method ad
System.out.println("Result: " + result); // Output: 'Result: 3'
}
}
Alternative 2 - Make method ad(int a, int b) static:
public class Sum {
public static int ad(int a, int b) { // Make method ad static
int add = (int) a + b;
return add;
}
public static void main(String[] args) {
int result = Sum.ad(1, 3); // Calling static method ad
System.out.println("Result: " + result); // Output: 'Result: 3'
}
}
Read more about diffrence between static and non-static methods here:
https://stackoverflow.com/questions/3903537/what-is-the-difference-between-a-static-method-and-a-non-static-method#:~:text=A%20static%20method%20belongs%20to%20the%20class%20and%20a%20non,class%20that%20it%20belongs%20to.&text=In%20the%20other%20case%2C%20a,class%20has%20already%20been%20instantiated.