Menu
Topics Index
...
`

Final keyword934


If you need explanation Read this topic

If you need Answer Take test on this topic

Final keyword934
What will be the output of the following program?
public class Final
{
    public static void main(String[] args)
    {
        final String result = "MERIT";
        final String assign;
        
        Final f = new Final();
        assign = "CAMPUS";

        final String xchange = " ";
        
        System.out.println(process(result, assign, xchange));
    }

    static String process(String a, String b, String xchange)
    {
        xchange = b + " " + a;

        return xchange;
    }
}

A. MERIT CAMPUS
B. CAMPUS MERIT
C. Compilation Error because the final variable xchange is initialised twice
D. Compilation Error for some other reason
E. 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 d, becz assign varbl didnt initilized n later it is initilized, we cant change the value of final variable,initially it is null,it must be null til the end

Posted by Uday Kumar    2014-02-17 03:43:37


ans B final variable assign is local to the main method in process method it is another variable

Posted by Ashok Reddi    2014-02-17 03:56:02


B.because xchange variable in main function is final but in process is normal variable so it can return CAMPUS MERIT

Posted by Venkatesh Kotte    2014-02-17 12:52:48


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

Posted by Merit Campus    2014-02-18 04:43:25


i didn't get any link....Merit Campus

Posted by Ashok Reddi    2014-02-19 05:39:28


© meritcampus 2019

All Rights Reserved.

Open In App