Java OCA OCP Practice Question 1949

Question

Which statements about the following program are true?.

public class Outer {
  public void doIt() {
  }//from  www  .  j  av  a  2s . com
  public class Inner {
    public void doIt() {
    }
  }

  public static void main(String[] args) {
    new Outer().new Inner().doIt();
  }
}

Select the two correct answers.

  • (a) The doIt() method in the Inner class overrides the doIt() method in the Outer class.
  • (b) The doIt() method in the Inner class overloads the doIt() method in the Outer class.
  • (c) The doIt() method in the Inner class hides the doIt() method in the Outer class.
  • (d) The full name of the Inner class is Outer.Inner.
  • (e) The program will fail to compile.


(c) and (d)

Note

The class Inner is a non-static member class of the Outer class and its full name is Outer.Inner.

The Inner class does not inherit from the Outer class.

The method named doIt is, therefore, neither overridden nor overloaded.

Within the scope of the Inner class, the doIt() method of the Outer class is hidden by the doIt() method of the Inner class.




PreviousNext

Related