Menu
Topics Index
...
`

Method Overloading236


If you need explanation Read this topic

If you need Answer Take test on this topic

Method Overloading236
What will be the output of the following program?
class MethodOverloading
{
    public static void main(String s[])
    {
        int i = 8;
        print(i);
        print();
        int j = 9;
        print(j);
    }

    public static void print()
    {
        System.out.println("Called print with no parameters");
    }

    public static void print(int i)
    {
        System.out.println("Called print with int parameter i");
    }

    public static void print(int j)
    {
        System.out.println("Called print with int parameter j");
    }
}

A. Called print with int parameter j
Called print with no parameters
Called print with int parameter i
B. Called print with int parameter i
Called print with no parameters
Called print with int parameter j
C. Compilation Error
D. Runtime Error
Topic: Method Overloading In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

ans is C because there is a same type of arguments in two print functions so compiler dont know which function to choose to execute

Posted by Adithya Aleti    2014-04-08 04:00:00


ans is C,when overloaded methods are called ,compiler differentiates the methods depending on their number,type ans sequence of parameters,here two prints methods have same number and same type of parameter so it leads to compilation error.

Posted by Raviteja Daggupati    2014-04-08 04:00:03


Ans is B in method overloading the methods can have same name with different parameters

Posted by Bharath Yelchuri    2014-04-08 04:38:45


Congratulations Adithya Aleti. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-04-09 03:59:37


© meritcampus 2019

All Rights Reserved.

Open In App