Java OCA OCP Practice Question 3096

Question

Consider the following program:

class Outer {/*from   w w w.  j  av a 2 s.co  m*/
        static class Inner {
                public final String text = "Inner";
        }
}
class Main {
        public static void main(String []args) {
                System.out.println(/*CODE HERE*/);
        }
}

Which one of the following expressions when replaced for the text in place of the comment /*CODE HERE*/ will print the output "Inner" in console?.

  • a) new Outer.Inner().text
  • b) Outer.new Inner().text
  • c) Outer.Inner.text
  • d) new Outer().Inner.text


a)

Note

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




PreviousNext

Related