in Education by
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 votes
by

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.

Related questions

0 votes
    What is the output of the following Java program? class Test { int i; } public class Main { public static void main (String ... test = new Test(); System.out.println(test.i); } }...
asked Nov 19, 2020 in Education by Editorial Staff
0 votes
    What is the output of the following Java program? What is the output of the following Java program? class Test { public static ... ) { System.out.println("Hello Javatpoint"); } } }...
asked Nov 17, 2020 in Education by Editorial Staff
0 votes
    What is the output of the following Java program? class Test { public static void main (String args[]) { System.out.println(10 ... * 20); } } The output of the above code will be...
asked Nov 17, 2020 in Education by Editorial Staff
0 votes
    What is the output of the following Java program? class Test { public static void main (String args[]) { System.out.println(10 ... ; System.out.println("Javatpoint" + 10 + 20); } }...
asked Nov 17, 2020 in Education by Editorial Staff
0 votes
    What will be the output of the following Java program? public class Test { public static void main( ... stackoverflow.com 🔗Source: Java Interview Questions and Answers...
asked Dec 19, 2020 in Technology by Editorial Staff
0 votes
    What is the output of the following Java program? class Test { int test_a, test_b; Test(int a, int b) { test_a = a; ... (); System.out.println(test.test_a+" "+test.test_b); } }...
asked Nov 19, 2020 in Education by Editorial Staff
0 votes
    What will be the output of the following Python program? z=set('abc') z.add('san') z.update(set(['p', 'q'] ... ;, ‘c’, [‘p’, ‘q’], ‘san}...
asked Jan 2, 2023 in Technology by JackTerrance
0 votes
    What will be the output of the following Python program? def foo(x): x[0] = ['def'] x[1] = ['abc'] return id(x) q = ['abc ... (id(q) == foo(q)) a) Error b) None c) False d) True...
asked Jan 2, 2023 in Technology by JackTerrance
0 votes
    What will be the output of the following Python program? z=set('abc') z.add('san') z.update(set(['p', 'q'] ... ;, ‘c’, [‘p’, ‘q’], ‘san}...
asked Jan 2, 2023 in Technology by JackTerrance
0 votes
    What will be the output of the following Python program? def foo(x): x[0] = ['def'] x[1] = ['abc'] return id(x) q = ['abc ... (id(q) == foo(q)) a) Error b) None c) False d) True...
asked Jan 2, 2023 in Technology by JackTerrance
0 votes
    What is the output of the following program? 3 . #include using namespace std; struct Time { int hours; int ... 20000 D. O 15000 Select the correct answer from above options...
asked Dec 27, 2021 in Education by JackTerrance
0 votes
    What is the output of the following program? 3 . #include using namespace std; struct Time { int hours; int ... 20000 D. O 15000 Select the correct answer from above options...
asked Dec 26, 2021 in Education by JackTerrance
0 votes
    What will be the output of the following program? public class MyFirst { public static void main(String[ ... stackoverflow.com 🔗Source: Java Interview Questions and Answers...
asked Dec 19, 2020 in Technology by Editorial Staff
...