1. interface I{ void f1(); // 1 public void f2(); // 2 protected void f3(); // 3 private void f4(); // 4 } which lines generate compile time errors?
  1. compiletime error at lines 1,2,3,4

  2. compiletime error at line 3

  3. compiletime error at line 1

  4. compiletime error at lines 3,4

  5. None of the above


Correct Option: D

AI Explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) compile time error at lines 1,2,3,4 - This option is incorrect. It suggests that there are compile time errors at all four lines, but this is not the case. There are no compile time errors at lines 1 and 2.

Option B) compile time error at line 3 - This option is incorrect. There is no compile time error at line 3. The "protected" access modifier is valid for interface methods.

Option C) compile time error at line 1 - This option is incorrect. There is no compile time error at line 1. The default access modifier is assumed if no access modifier is specified, making the method accessible to any class within the same package.

Option D) compile time error at lines 3,4 - This option is correct. There is a compile time error at line 4. The "private" access modifier is not allowed for interface methods. Additionally, there is no compile time error at line 3.

Option E) None of the above - This option is incorrect. As explained above, option D is the correct answer.

Therefore, the correct answer is D) compile time error at lines 3,4. This option is correct because the "private" access modifier is not allowed for interface methods.

Find more quizzes: