Menu
Question Index
...

What will be the output of the following program?

class MethodOverloading
{
    public static void main(String s[])
    {
        A a = new A();
        int x = a.method1(4, 5); // LINE X
    }
}

class A
{
    void method1(int a)
    {
        System.out.println("method1 with a called");
    }

    void method1(int a, int b)
    {
        System.out.println("method1 with a and b called");
    }

    int method1(int a, int b) // LINE Y
    {
        System.out.println("method1 which returns int is called");
    }
}


method1 with a and b called
method1 which returns int is called
Compilation Error at LINE Y - since we can not have two methods
with same method name and parameters
Runtime Error at LINE X - since it does not know which method1 should be called.

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