Java OCA OCP Practice Question 3085

Question

Given this class definition:

class Outer {
    static class Inner {
        public final String text = "Inner";
    }
}

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?.

public class Main {
    public static void main(String []args) {
        System.out.println(/*CODE HERE*/);
    }
}
  • 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