package simplejava; public class TestMain1 { TestMain1() { System.out.println("I am in Constructor"); } TestMain1(String message) { System.out.println("Message " + message); } public void main(String[] args) { TestMain1 nm = new TestMain1(); TestMain1 nm1 = new TestMain1("Hello"); } }

  1. Exception

  2. Compiler Error

  3. I am in Constructor

  4. Message Hello


Correct Option: A

AI Explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) Exception - This option is incorrect because there is no exception mentioned or thrown in the code.

Option B) Compiler Error - This option is incorrect because the code does not contain any compilation errors.

Option C) I am in Constructor - This option is correct because when the TestMain1 object nm is created using the default constructor TestMain1(), the message "I am in Constructor" will be printed.

Option D) Message Hello - This option is correct because when the TestMain1 object nm1 is created using the constructor TestMain1(String message) with the argument "Hello", the message "Message Hello" will be printed.

The correct answer is C. I am in Constructor. This option is correct because the code will print "I am in Constructor" when the TestMain1 object nm is created using the default constructor.

Find more quizzes: