Exam 1z0-819 All QuestionsBrowse all questions from this exam
Question 113

Given:

Which code fragment added to line 1 enables the code to compile and print Hello Joe?

    Correct Answer: D

    The code requires a non-static inner class to be instantiated within the outer class before its methods can be accessed. The inner class Greeting used in the provided snippet must not contain static methods because non-static inner classes cannot have static methods. Therefore, the correct code fragment must declare the inner class Greeting within the outer class App and make its greet method accessible. Unlike other options, the class declaration in option D correctly allows an instance of the Greeting class to be instantiated by an instance of the outer class App and call its method, resulting in the desired output 'Hello Joe'.

Discussion
ASPushkinOption: C

answer: C D. failed new Greeting().greet("Joe"); A. failed interface could not be initialized B. failed static methods not allowed in the Inner class

d7bb0b2Option: C

C IS CORRECT: a: INCOORECT GREET IS NOT A FIELD AND INTERFAZ CANNOT BE CREATE AS INSTANCE b: INCORRECT INNER CLASS NOT STATIC CANNOT HAVE STATIC METHOD D: STATIC CLASS CANNOT INSTANCIATED => new ExamTopics113.Greeting().greet("Joe"); => is correct

SampsOption: C

C is correct. B is wrong because static is not allowed in methods in inner classes in Java 1. Tested

Ashan_OzlovOption: B

Both B and C work here! Tested

dilleman

B and C both works

StavokOption: C

C is correct Tested