Menu
Topics Index
...
`

Final keyword951


If you need explanation Read this topic

If you need Answer Take test on this topic

Final keyword951
What will be the output of the following program?
class Result
{
    public static void main(String args[])
    {
        A b = new B();
        System.out.println("x = " + b.getResult(0, 1));  
    }
}

class B extends A
{
    final public int getResult(int a, int b) { return a + b; }
}

class A extends Result
{
    public int getResult(int a, int b) { return a * b; }
}

A. x = 0
B. x = 1
C. Compilation Error
D. Runtime Error
Topic: final Keyword In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

ans b.
class b methd declare with final.
so result 1.
final value cant chngd

Posted by Maheshwari Natarajan    2014-09-11 08:35:14


ans is B.
we can override a non-final method to final method. it doesn't give compilation error.
As method is overridden it will call method in class B which returns a+b i.e., ans is "x = 1".

Posted by Gopinath Manchikanti    2014-09-11 09:13:03


ans is B.we can override a non-final method to final method. it doesn't give compilation error.As method is overridden it will call method in cla

Posted by Shamee Shamee    2014-09-11 12:29:24


Congratulations Maheshwari Natarajan. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-09-12 04:03:43


© meritcampus 2019

All Rights Reserved.

Open In App