What is the result of the following Java program?

Solution:

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.

0 answers