Java OCA OCP Practice Question 2997

Question

Choose the correct option based on this program:

class base1 {// w ww .ja  v a  2s . co m
    protected int var;
}

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

class Main 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 marked with the comment #1
  • b) the program will report a compilation error at statement marked with the comment #2
  • c) the program will report a compilation error at statement marked with the comment #3
  • d) the program will compile without any errors


c)

Note

Statements marked with the comment #1 and #2 will not result in any compiler errors; only access to the variable var will generate a compiler error since the access is ambiguous (since the variable is declared in both base1 and base2).




PreviousNext

Related