Plis i need help with this class | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 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

5th Aug 2018, 4:55 AM
stephen haokip
stephen haokip - avatar
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
5th Aug 2018, 5:10 AM
Ipang