Knowee
Questions
Features
Study Tools

Select the correct answerWhat will be the output of the following Java programclass recursion { int func (int n) { int result; result = func (n - 1); return result; } } class Output { public static void main(String args[]) { recursion obj = new recursion() ; System.out.print(obj.func(12)); } }OptionsCompilation Error10Runtime Error

Question

Select the correct answerWhat will be the output of the following Java programclass recursion { int func (int n) { int result; result = func (n - 1); return result; } } class Output { public static void main(String args[]) { recursion obj = new recursion() ; System.out.print(obj.func(12)); } }OptionsCompilation Error10Runtime Error

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

The correct answer is "Runtime Error".

This is because the function "func" is a recursive function, which means it calls itself. However, there is no base case to stop the recursion. In this case, the function will keep calling itself with a decreasing value of n (n-1) until it eventually tries to compute "func" of a negative number, which is not defined in the function. This will cause a StackOverflowError, which is a specific type of runtime error.

This problem has been solved

Similar Questions

Select the correct answerWhat will be the output of the following Java program? class recursion { int fact(int n) { int result; if (n == 1) return 1; result = fact(n - 1) * n; return result; } } class Output { public static void main(String args[]) { recursion obj = new recursion() ; System.out.print(obj.fact(1)); } }Options 120301Runtime Error

the correct answerWhat is Recursion in Java?

Select the correct answerWhat will be the output of the given Java program? abstract class java {    int x;    abstract void display(); }     class method extends java {     int y;     void display() {        System.out.println(y);     } }     class Abstract_demo {     public static void main(String args[]) {         method obj = new method();         obj.y = 1;         obj.display();         } }OptionsRuntime Error10Compilation Error

Select the correct answerWhat will be the output of the following Java program?class main_class   {    public static void main(String args[])    {      int code = 10;      if (code == 10)       {         int code = 6;        System.out.println(code);      }    }   }OptionsCompilation error610Runtime error

What is the output of the following code?public class Solution { static int x = 10; public static void main(String args[]) { System.out.println(x); } }Options: Pick one correct answer from below100Compilation errorRuntime error

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.