Java OCA OCP Practice Question 3254

Question

Consider the following program and predict the behavior:

class base1 {//from  w  ww  .  j  av  a 2  s .c o m
    protected int var;
}

interface base2 {
     int var = 0; // #1
}

class Test extends base1 implements base2 { // #2
    public static void main(String args[]) {
            System.out.println("var:" + var); // #3
    }
}
  • a) The program will report a compilation error at statement #1.
  • b) The program will report a compilation error at statement #2.
  • c) The program will report a compilation error at statement #3.
  • d) The program will compile without any errors.


c)

Note

Statement #1 and #2 will not raise any alarm; only access to the variable var will generate an error since the access is ambiguous (since the variable is declared in both base1 and base2).




PreviousNext

Related