Parameter question | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Parameter question

Does Static int fun(int a=1) make garbage value?

6th Aug 2020, 4:39 PM
Zwe Thu
Zwe Thu - avatar
5 Answers
+ 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)?
6th Aug 2020, 4:46 PM
Ipang
+ 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 .
6th Aug 2020, 9:12 PM
Jayakrishna 🇮🇳
+ 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.
7th Aug 2020, 5:04 AM
Zwe Thu
Zwe Thu - avatar
+ 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; } }
7th Aug 2020, 5:05 AM
Zwe Thu
Zwe Thu - avatar
+ 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.
7th Aug 2020, 7:12 AM
Ipang