Java OCA OCP Practice Question 2087

Question

Consider the following code and choose the right option for the word <access-modifier>:.

// Shape.java/*  ww w.  jav  a2 s  .com*/
public class Shape {
     protected void display() {
             System.out.println("Display-base");
      }
}

// Circle.java
public class Circle extends Shape {
     <access-modifier> void display(){
             System.out.println("Display-derived");
     }
}
  • A. Only protected can be used
  • B. public and protected both can be used
  • C. public, protected, and private can be used
  • D. Only public can be used


B.

Note

You can provide only a less restrictive or same-access modifier when overriding a method.




PreviousNext

Related