Java | Functions | Question 6

Predict the output?

filter_none

edit
close

play_arrow

link
brightness_4
code

class Main {
    public static void main(String args[]) {   
             System.out.println(fun());
    }   
    static int fun(int x = 0)
    {
      return x;
    }
}

chevron_right


(A) 0
(B) Garbage Value
(C) Compiler Error
(D) Runtime Error


Answer: (C)

Explanation: Java doesn’t support default arguments. In Java, we must write two different functions.

Quiz of this Question



My Personal Notes arrow_drop_up


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.