Given:
Which code fragment added to line 1 enables the code to compile and print Hello Joe?
Given:
Which code fragment added to line 1 enables the code to compile and print Hello Joe?
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'.
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
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
C is correct. B is wrong because static is not allowed in methods in inner classes in Java 1. Tested
Both B and C work here! Tested
B and C both works
C is correct Tested