Menu
Topics Index
...
`

Method Overloading to print datatypes


If you need explanation Read this topic

If you need Answer Take test on this topic

Method Overloading to print datatypes
What will be the output of the following program?
public class TrzIt {
    public static void book(short a) {
        System.out.print("short ");
    }
    public static void book(Short a) {
        System.out.print("SHORT ");
    }
    public static void book(Long a) {
        System.out.print("LONG ");
    }
    public static void main(String[] args) {
        Short shortRoom = 1;
        int intRoom = 2;
        book(shortRoom);
        book((short) intRoom);
    }
}

A. SHORT SHORT
B. short short
C. short SHORT
D. SHORT short
E. Some other output
F. Compilation Error or 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 D:following the type matching of the parameters and type casting in the second case

Posted by Krishna Murthy    2013-07-11 04:05:04


Ans is B.. since we are converting intRoomto short.. so it goes 1st book function..

Posted by Om Prakash Om    2013-07-11 04:31:39


Congratulations Krishna Murthy, you are this dose winner. Please send us your mobile details and we will process the recharge asap.

Posted by Merit Campus    2013-07-11 11:57:21


thanku mc received rc :)

Posted by Krishna Murthy    2013-07-22 15:27:50


© meritcampus 2019

All Rights Reserved.

Open In App