Menu
Topics Index
...
`

Final keyword


If you need explanation Read this topic

If you need Answer Take test on this topic

Final keyword
What will be the output of the following program?
public class Final
{
    final int assign = 30;    

    public static void main(String[] args)
    {
        final int result = 20;
        final int assign;
        
        Final f = new Final();
        assign = 20;

        System.out.println(assign);
        System.out.println(f.assign);
        System.out.println(f.process(result));
    }

    int process(int a)
    {
        return a + 5;
    }
}

A. 20
20
25
B. 20
30
25
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 is c because final variable "assign" is declared 2 times....

Posted by Nanda Kishore    2014-03-11 03:35:48


Ans b:wen are printng assign it wl pprint local carble value,wen we are ptntg wt f.assign it wl print instance varble, we are passiing 20 to process thn it wl return 20+5

Posted by Uday Kumar    2014-03-11 03:41:28


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

Posted by Merit Campus    2014-03-12 04:25:47


© meritcampus 2019

All Rights Reserved.

Open In App