Question 32Asked in DSSSB TGT Computer Science (Technical), 13 Sep 2025, Shift 3 (5:00 PM)

What will be the output of the following code? class Test {

What will be the output of the following code? class Test { Test(int x) { System.out.println("Parameterized Constructor"); } Test() { this(10); System.out.println("Default Constructor"); } public static void main(String[] args) { Test obj = new Test(); } }
  1. AParameterized Constructor followed by Default Constructor
  2. BCompilation Error
  3. CDefault Constructor
  4. DParameterized Constructor
Show answerHide answer

Correct answer: (A) Parameterized Constructor followed by Default Constructor

Explanation

new Test() calls the no-argument constructor. Its first statement, this(10), runs the parameterized constructor first, so "Parameterized Constructor" is printed and then "Default Constructor".

From DSSSB TGT Computer Science PYQ (Technical), 13 Sep 2025, Shift 3 (5:00 PM)

This is question 32 of DSSSB TGT Computer Science PYQ (Technical), 13 Sep 2025, Shift 3 (5:00 PM). See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.