0
Parameter question
Does Static int fun(int a=1) make garbage value?
5 ответов
+ 1
Does the function has a body?
And what you mean by garbage value? did you set the function to return anything as per the definition (return an int)?
+ 1
According me ,in java you cannot assign values in argument list.. So it is error.. (not support default value assignment)
And also java, requires assigning values before you use strictly so it error, dont produce garbage values .
+ 1
Ipang I will show u the whole code.It is a sololearn challenge question.The given answers are 0, compile error, runtime error,garbage value.
+ 1
Ipang here is code
public class Main
{
public static void main(String[] args) {
System.out.print(fun());
}
static int fun (int x = 0){
return x;
}
}
+ 1
I guess the answer was compile error, because I got that when I tried the code. As Jayakrishna said, Java doesn't support default argument. And AFAIK Java doesn't have garbage value issue, primitive variables are initialized to a default value most of the time.