Exam 1z0-811 All QuestionsBrowse all questions from this exam
Question 5

Given:

And the code fragment:

Which code fragment can be inserted at line n1 to enable the code to print All the best?

    Correct Answer: C

    To enable the code to print 'All the best,' the method 'writeMsg()' should be called within the 'readMsg()' method. In Java, methods within the same class can be directly invoked using their names. Since 'writeMsg()' is an instance method and not a static method, calling 'writeMsg()' directly within 'readMsg()' is the correct approach. Therefore, the correct code fragment to be inserted at line n1 is 'writeMsg();'.

Discussion
falchettoOption: C

B Is wrong. Would be correct if the readMsg was declared as static, but it isn't. Correct answer is C.

Ross_2023Option: C

C is the correct answer because, a method can access another method within a class directly. writeMsg() is an instance method and not a static method. B is incorrect because Messenger.writeMsg() implies as if writeMsg() is a static method. In order B to be correct, keyword "static" should be explicitly declared in writeMsg() method.

Olha88Option: C

B is NOT correct answer!

supercoderOption: C

c is correct .

yonathanmartinezOption: C

Se puede llamar el un método publico dentro de otro método dentro de la misma clase