0
Debug the error and please explain !!
public class MyClass { public static void main(String[ ] args) { int x = 5; int y = addOneTo(x); System.out.println(y); } static void addOneTo(int x) { x = x + 1; } }
4 Respostas
+ 2
your return type for addOneTo method is void but in int y=addOneTo(x); statement you are trying to assign your void type to int type. so error occurs.. To fix it declare addOneTo method as int type
0
How
0
static int addOneTo(int x) {
return x + 1;
}
0
i know the answer but why? why can't we use void type? methods can be of any type..