What will be the output for the below program

class GFG 
{ 
    int a = 0, b = 0;
     GFG()
    {
        this(10, 20);
        System.out.println(10 + 30);
    }
    
     GFG(int a, int b)
    {
        this.a = a;
        this.b = b;
        System.out.println(a + b);
    }
    public static void main(String[] args) 
    { 
        GFG obj = new GFG();
    } 
}  

(A) 40
30
(B) 30
40
(C) 0
0
(D) Compile error


Answer: (B)

Explanation:
If a class has two constructor one with no arguments and other with arguments then one with have argument can be called from without argument.

Quiz of this Question


  • Last Updated : 20 Nov, 2018

Share your thoughts in the comments