Java OCA OCP Practice Question 3244

Question

Consider the following program and choose the right option from the given list:

class Base {//from  www  . j  av  a2  s. c o  m
     public void test() {
             protected int a = 10;          // #1
     }
}

class Test extends Base {                   // #2
     public static void main(String[] args) {
             System.out.printf(null);       // #3
     }
}
  • a) The compiler will report an error at statement #1.
  • b) The compiler will report an error at statement #2.
  • c) The compiler will report errors at statement #3.
  • d) The program will compile without any error.


a)

Note

Statement #1 will result in a compiler error since the keyword protected is not allowed inside a method body.




PreviousNext

Related