Menu
Topics Index
...
`

Final keyword931


If you need explanation Read this topic

If you need Answer Take test on this topic

Final keyword931
What will be the output of the following program?
public class Final
{
    int lanif = 37;
    int nafi = 21;

    public static void main(String[] args)
    {
        final Final f = new Final();
        f.process2();

        f = modify(f);
        f.process();
    }

    public static final Final modify(final Final f)
    {
        f.process();

        Final f2 = new Final();
        f2.process();

        return f2;
    }

    final void process()
    {
        lanif = nafi + nafi;
        System.out.print(lanif + " " + nafi + " ");
    }

    void process2()
    {
        nafi = lanif % 2;
        System.out.print(nafi + " " + lanif + " ");
    }
}

A. 1 37 2 1 42 21 42 21
B. 18 37 36 18 42 21 42 21
C. 1 37 2 1 1 37 2 1
D. Compilation 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. as object f is defined as a final object, its value cannot be changed  ( f = modify(f) gives error)

Posted by Nikhil Sulibhavi    2014-06-16 13:15:07


answer is c

Posted by Vinod Avulapati    2014-06-16 13:15:35


Ans is D..final varibles cant be changed through the program

Posted by Uday Kumar    2014-06-16 13:16:19


Anwer : D we cannot assign values to the final variable f

Posted by Deepak Kumar Yadav    2014-06-16 13:16:50


ans is D because object values not defined

Posted by Vijaya Vijaya    2014-06-17 05:26:30


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-06-18 04:01:46


© meritcampus 2019

All Rights Reserved.

Open In App