Multiple choice technology programming languages

package overriding; class Super5 { int testAdd(int x,int y) { System.out.println("Super Add "+(x+y)); return(x+y); } } public class TestOverrideSub5 extends Super5{ long testAdd(int x,int y) { System.out.println("Sub Add "+(x+y)); return(x+y); } public static void main(String[] args) { Super5 s5 = new TestOverrideSub5(); s5.testAdd(5,5); } }

  1. Compiler Error

  2. Exception

  3. Sub Add 10

  4. Super Add 10

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Overriding requires identical method signatures including return type. Changing return type from int to long with the same parameters is not a valid override in Java. This causes a compiler error.

AI explanation

The subclass method has the same name and parameters as the superclass method but a different, non-covariant return type (long vs int). Java requires an overriding method's return type to be the same or a covariant (subtype) reference type — primitive widening like int to long doesn't count as covariant. This return-type clash is a compile-time error, so the code never runs.