Menu
Topics Index
...
`

Return statement and Ternary Operator


If you need explanation Read this topic

If you need Answer Take test on this topic

Return statement and Ternary Operator
What will be the output of the following program?
public class Facts {
    public static void main(String[] args) {
        System.out.println(Fact.fact(5));
    }
}
class Fact {
    int fact(int n) {
        return n > 1 ? (fact(n - 1) * n) : 1;
    }
}

A. 120
B. 1
C. Some other output
D. Compilation Error or Runtime Error
Topic: Static and Non Static Variables - Static and Non Static Methods

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.

answer is compilation error as  int fact is not a static method

Posted by Shiva Kaushik    2013-09-17 03:31:36


D bcoz...fact(int) is a non-static method,hence it can not be referenced from static context.

Posted by Bhavya Rishitha    2013-09-17 04:43:38


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

Posted by Merit Campus    2013-09-18 03:40:32


© meritcampus 2019

All Rights Reserved.

Open In App