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


Correct Option: D

AI Explanation

To answer this question, let's go through each line to understand if it generates a compile-time error:

1) void f1(); - This line does not generate a compile-time error because the default access modifier for interface methods is public.

2) public void f2(); - This line does not generate a compile-time error because the access modifier public is allowed for interface methods.

3) protected void f3(); - This line generates a compile-time error because the access modifier protected is not allowed for interface methods. Interface methods can only have public access modifier.

4) private void f4(); - This line generates a compile-time error because the access modifier private is not allowed for interface methods. Interface methods can only have public access modifier.

Therefore, the correct answer is option D) compile time error at lines 3,4.

Find more quizzes: