Skip to content
Related Articles

Related Articles

Java | Functions | Question 6
  • Last Updated : 07 Jan, 2014

Predict the output?




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

(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

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up