- 1
Plis i need help with this class
public class Program { public static void main(String[ ] args) { int res = max(7, 42); System.out.println(res); } } public class Maximum{ static int max(int a, int b) { if(a > b) { return a; } else { return b; } } } where did i go wrong
1 Answer
+ 4
The max method is a static method declared in Maximum class, you don't need an instance to access a static method, you can just invoke the method by mentioning the class to which the method belongs.
int res = Maximum.max(7, 42);
Hth, cmiiw