Multiple choice

class extractsample10a { public static void main(String []args) { System.out.println(/HERE/); } } class sample10 { static class sample10a { public final String text = "hello"; } } What is that expression in /HERE/ so that "hello" can be printed?

  1. sample10.new sample10a().text

  2. new sample10.sample10a().text

  3. sample10.sample10a.text

  4. new sample10().sample10a.text

  5. none of the above

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The correct way to access fields of the static inner class is to use the inner class instance along with the outerclass, so new sample10.sample10a().text will do the job.