Oracle
1Z0-819 · Question #56
Given public class Hello { class Greeting { void sayHi() { System.out.println("Hello world"); } } public static void main(String[] args) { // Line 1 } } What code must you insert on Line 1 to enable…
The correct answer is B. B. Hello myH = new Hello(); Hello.Greeting myG = myH.new Greeting(); myG.sayHi(). See the full explanation below for the reasoning.
Question
Given
public class Hello {
class Greeting {
void sayHi() {
System.out.println("Hello world");
}
}
public static void main(String[] args) { // Line 1
}
}
What code must you insert on Line 1 to enable the code to print Hello world?
Options
- AA. Hello.Greeting myG = new Hello.Greeting().myG.sayHi();
- BB. Hello myH = new Hello(); Hello.Greeting myG = myH.new Greeting(); myG.sayHi();
- CC. Hello myH = new Hello(); Greeting myG = myH.new Greeting(); myG.sayHi();
- DD. Hello myH = new Hello(); Greeting myG = new Greeting(); myG.sayHi();
How the community answered
(21 responses)- A5% (1)
- B81% (17)
- C10% (2)
- D5% (1)
Community Discussion
No community discussion yet for this question.