class C1{ public void m1(){ // 1 } } class C2 extends C1{ //2 private void m1(){ } }

  1. compile time error at line1

  2. compile time error at line2

  3. Run time exception

  4. None Of the above


Correct Option: B

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 line 1 - This option is incorrect because there is no compile time error at line 1. The method m1() in class C1 is declared correctly.

Option B) compile time error at line 2 - This option is correct because there is a compile time error at line 2. In class C2, the method m1() is attempting to override the method m1() in the parent class C1. However, the method m1() in the parent class C1 is not accessible from the subclass C2 because it is declared as private. Therefore, the subclass cannot override it, resulting in a compile time error.

Option C) Run time exception - This option is incorrect because the code does not contain any runtime exceptions. The error occurs during compilation, not during runtime.

Option D) None of the above - This option is incorrect because the correct answer is option B, as explained above.

The correct answer is B) compile time error at line 2. This option is correct because the method m1() in class C2 cannot override the private method m1() in class C1.

Find more quizzes: