1z0-819 Exam QuestionsBrowse all questions from this exam

1z0-819 Exam - Question 113


Given:

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

Show Answer
Correct Answer: CD

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

6 comments
Sign in to comment
StavokOption: C
Jul 19, 2023

C is correct Tested

dilleman
Sep 29, 2023

B and C both works

Ashan_OzlovOption: B
Oct 5, 2023

Both B and C work here! Tested

SampsOption: C
Dec 30, 2023

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

d7bb0b2Option: C
Jan 8, 2024

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

ASPushkinOption: C
May 31, 2024

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