Menu
Question Index
...

What will be the output of the following program?

class MethodOverloading
{
    public static void main(String s[])
    {
        print();
        print(8);
        int j = print(9);
    }

    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 with return type void");
    }

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


Called print with no parameters
Called print with int parameter with return type void
Called print with int parameter with return type int
Compilation Error - since there are two methods with int parameter but return type is different.
Compilation Error - since there are three methods with the same name print.
Runtime Error - It fails with a runtime error, since it does not know which print method to call.

Doubts

Problems

Topic: Method Overloading In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App