Menu
Topics Index
...
`

Final keyword932


If you need explanation Read this topic

If you need Answer Take test on this topic

Final keyword932
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(process(result));
    }

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

A. 20
25
B. Compilation Error because assign variable is declared twice
C. Compilation Error for some other reason
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.

B,is the answer.final variables cannot hold diffrnt values once asigned

Posted by Shabaaz Shaikz    2014-02-11 08:13:31


C) Since process() is a non static method which cannot be referenced in a static method, i.e., main method.
If the process() method is static the the output would be
20
25

Posted by Nikhil Sulibhavi    2014-02-11 08:17:10


A is the answer
because  at local scope the value of final variable not depends no global variable

Posted by Suku Sukumar    2014-02-11 08:20:42


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

Posted by Merit Campus    2014-02-12 03:49:51


© meritcampus 2019

All Rights Reserved.

Open In App