QuestionQ106

Working with Methods and Encapsulation

Given the following code fragment:

Question Image

Test.java:

Question Image

What is the result?

  • A
  • D Compilation fails in the Test class.
  • E Both the Employee class and the Test class fail to compile.
Explanation

The Employee class does not compile because two method-invocation statements are missing semicolons, and a constructor invocation using this(...) must be the first statement in a constructor body. The Test class also does not compile because Employee has no no-argument constructor, yet it is instantiated with new Employee().

Community Discussion

No comments yet. Be the first to start the discussion!