Header Ads Widget

Predict the output

Predict the output

What will be the output of the following code?

class Test 
    int a; 
    int b; 
        this(10, 20);   
        System.out.print("constructor one "); 
    Test(int a, int b) 
        this.a = a; 
        this.b = b; 
        System.out.print("constructor two "); 
class new_test{
    public static void main(String[] args) 
        Test object = new Test(); 
This problem has only one correct answer

Ans:-  3
Solution Description
When the object of Test class is created,the constructor with no arguments is called.
When  this(10,20) is encountered , the constructor with two arguments int and int is called because this is the reference of the object. So using this way we can call more than one constructor.

Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-

Companies interview:-

Full C course:-    

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-


Post a Comment