0
What is the output of the following Java program?

Open 1 Answers 21 Views Education
What is the output of the following Java program?

public class Test   

{  

    Test(int a, int b)  

    {  

        System.out.println("a = "+a+" b = "+b);  

    }  

    Test(int a, float b)  

    {  

        System.out.println("a = "+a+" b = "+b);  

    }  

    public static void main (String args[])  

    {  

        byte a = 10;   

        byte b = 15;  

        Test test = new Test(a,b);  

    }  

}

1 Answer

0

What is the output of the following Java program?

public class Test   

{  

    Test(int a, int b)  

    {  

        System.out.println("a = "+a+" b = "+b);  

    }  

    Test(int a, float b)  

    {  

        System.out.println("a = "+a+" b = "+b);  

    }  

    public static void main (String args[])  

    {  

        byte a = 10;   

        byte b = 15;  

        Test test = new Test(a,b);  

    }  

}  

The output of the following program is:

a = 10 b = 15

Here, the data type of the variables a and b, i.e., byte gets promoted to int, and the first parameterized constructor with the two integer parameters is called.

by (53.7k points)
...