Examveda
Examveda

What is output of the program?
class Test{
        public void display(int x, double y){
                System.out.println(x+y);
        } 
        public double display(int p, double q){
                return (p+q);
        }
        public static void main(String args[]){
                Test test = new Test();
                test.display(4, 5.0);
                System.out.println(test.display(4, 5.0));
        }
}

A. 9.0 9.0

B. 9 9

C. Compilation Error

D. None of these

Answer: Option C


This Question Belongs to Java Program >> Overriding And Overloading

Join The Discussion

Comments ( 12 )

  1. MANJUL PRAKASH
    MANJUL PRAKASH :
    3 years ago

    Arise a ambigutity problem because parameter of both function are same then compiler confuse which function called.

  2. Ruçhi Jaiñ
    Ruçhi Jaiñ :
    4 years ago

    Because different return type is not sufficient to overload a method

  3. Mohammad Shahrukh
    Mohammad Shahrukh :
    5 years ago

    An overloaded method may or may not have different return types. But return type alone is not sufficient for the compiler to determine which method is to be executed at run time. It is not possible to have a method with same parameters and different return type.

  4. Hüseyin Torun
    Hüseyin Torun :
    5 years ago

    it is working and the correct answer is A.

  5. Gaddapara Swapna
    Gaddapara Swapna :
    6 years ago

    test.display(4,5.0) faces ambiguity(confusion) problem, whether it access void display method (or) double display method

  6. Ram Naveen
    Ram Naveen :
    6 years ago

    There is no point of overloading methods based on return types

  7. Ankit Kumar
    Ankit Kumar :
    6 years ago

    overloading concept definition clearly says that the parameters based on no. of arguments or data types or order of arguments should be different.But here the
    no. of argument or data types or order of argument is same.hence compilation error.

  8. Madhu Velpuri
    Madhu Velpuri :
    6 years ago

    The method println(boolean) in the type PrintStream is not applicable for the arguments (void)

  9. Mahesh MR
    Mahesh MR :
    7 years ago

    There is a duplication of method, in method overloading the return type is not considered. The number of parameter are same, sequence is same and the datatype is same. There occurs a compilation error.

  10. Sandy Negi
    Sandy Negi :
    7 years ago

    for function overloading return type of the function should also be same

  11. Govind Lalam
    Govind Lalam :
    7 years ago

    Change in return type is not valid for method overloading..

  12. Govind Lalam
    Govind Lalam :
    7 years ago

    Change in return type is not valid for method overloading..

Related Questions on Overriding and Overloading