Menu
Topics Index
...
`

Method Overloading


If you need explanation Read this topic

If you need Answer Take test on this topic

Method Overloading
What will be the output of the following program?
class MethodOverloading
{
    public static void main(String s[])
    {
        print();
        print(8);
        print(20 < 10);
    }

    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");
    }

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

A. Called print with no parameters
Called print with int parameter
Called print with boolean parameter
B. Compilation Error - Since we can not have same method name print for 3 methods
C. Compilation Error - Since we need to have a different return type for each method
D. Called print with no parameters
Called print with int parameter
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.

answer is A as first print call print with no arguments , second print calls print with int argument, and third will result in bollean values.

Posted by Ashok Kumar Paritala    2014-08-06 03:55:39


A is ans.. fist print() method did not contain any parameters... so it prints first print() method statement. in 2nd print() method we are passing int parameter so it prints statement in 2nd print() method...similarly 3rd method works in the samw way..

Posted by Sareesh Rayapati    2014-08-06 04:04:33


A

Posted by Prabhakar Reddy    2014-08-06 05:28:34


A :D

Posted by Soundarya Sathish    2014-08-06 10:03:01


Congratulations Ashok Kumar Paritala. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-08-07 04:48:47


© meritcampus 2019

All Rights Reserved.

Open In App