Declarations and Access Control

Q1: What will be the output of the program?
class A 
{
    final public int GetResult(int a, int b) { return 0; } 
} 
class B extends A 
{ 
    public int GetResult(int a, int b) {return 1; } 
} 
public class Test 
{
    public static void main(String args[]) 
    { 
        B b = new B(); 
        System.out.println('x = ' + b.GetResult(0, 1));  
    } 
}

A An exception is thrown at runtime.

B x = 1

C x = 0

D Compilation fails.

ANS:A - x = 0

The code doesn't compile because the method GetResult() in class A is final and so cannot be overridden.



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.