Menu
Topics Index
...
`

Recursive Method Output


If you need explanation Read this topic

If you need Answer Take test on this topic

Recursive Method Output
What will be the output of the following program?
class Recursion
{
    public static void main(String[] args)
    {
        int ma = 35;
        int in = 67;
        int sta = recurse(ma, in);
        System.out.println("static = " + sta + "tic");
    }

    public static int recurse(int pub, int lic)
    {
        if (pub % 13 == 0)
        {
            return pub + lic;
        }
        return recurse(pub++, lic / 2);
    }
}

A. static = 41tic
B. static = 47tic
C. static = 43tic
D. Compilation Error
E. Throws StackOverflowError
Topic: Recursive 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.

E.bcz recursively goes on printing Rec.recurse.and throws stack overflow

Posted by Shabaaz Shaikz    2014-04-07 13:00:41


ans is E. Throws StackOverFlowError because the statement recurse(pub++,lic/2) is invoked irrespective of the condition specified in if statement.

Posted by Nikhil Sulibhavi    2014-04-07 13:00:54


c

Posted by Rocky Naveen    2014-04-07 14:40:03


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

Posted by Merit Campus    2014-04-08 03:47:51


ThankQ...:-)

Posted by Shabaaz Shaikz    2014-04-08 08:47:29


© meritcampus 2019

All Rights Reserved.

Open In App