Given the following code, what will be the outcome?
public class MyClass extends java.lang.Math { public int add(int x, int y) { return x + y; } //from w ww .j av a2 s.c om public int sub(int x, int y) { return x - y; } public static void main(String [] a) { MyClass f = new MyClass(); System.out.println("" + f.add(1, 2)); } }
C.
The code does not compile because it extends the Math class.
Math class has been declared as final.
A class cannot extend a class that has been declared final.