Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Look at the following code. Which line will cause a compiler error? Line 1 publi

ID: 3836134 • Letter: L

Question

Look at the following code. Which line will cause a compiler error? Line 1 public class ClassA Line 2 {Line 3 public ClassA () Line 4 public int methodi (int a) {} Line 5 public final int method2(double b) {} Line 6} Line 7 public ClassB extends ClassA Line 8 {Line 9 public ClassB () {} Line 10 public int method 1 (int b) {} Line 11 public int method2 (double c) {} Line 12} Look at the following code. The method in line __________ will override the method in line __________. Line 1 public class ClassA Line 2 {Line 3 public ClassA () Line 4 public int methodi (int a) {} Line 5 public int method2(int b) {} Line 6} Line 7 public ClassB extends ClassA Line 8 {Line 9 public ClassB () {} Line 10 public int method 1 (int b) {} Line 11 public int method2 (double c) {} Line 12}

Explanation / Answer

21) Compiler error at Line 11

Reason

Here method2 in ClassA at Line 5 is declared as final.

* Final methods cannot be overridden.

So, we get compilation error at line 11.

22) 10,4

The method in Line 10 will override the method in Line 4

Reason

method1 in ClassB has same name as its parent class, same number and type of parameters and same return type as "int" as method1 in ClassA. So, method1 in ClassB overrides the method1 in ClassA.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote