Consider the following JAVA program : public class First { public static int CBSE (int x) { if (x < 100) x = CBSE (x + 10); return (x – 1); } public static void main (String[] args){ System.out.print(First.CBSE(60)); } } What does this program print ?
95
The recursive method keeps calling itself with x + 10 while x is below 100, and on the way back each level subtracts 1 from the value returned by the deeper call. The output is the value returned by the outermost call with argument 60.
Step 1 — The calls go 60 → 70 → 80 → 90 → 100. At x = 100 the condition x < 100 is false, so no further call is made and the method returns 100 − 1 = 99.
Step 2 — Unwinding: the call with 90 receives 99, stores it in x and returns 98; the call with 80 returns 97; the call with 70 returns 96; the call with 60 returns 95.
| Call | x on entry | x after inner call | Returns |
|---|---|---|---|
| call(100) | 100 | 100 (no recursion) | 99 |
| call(90) | 90 | 99 | 98 |
| call(80) | 80 | 98 | 97 |
| call(70) | 70 | 97 | 96 |
| call(60) | 60 | 96 | 95 |
Step 3 — main prints the outermost return value, 95.
59 would be the result of returning x − 1 without the recursive assignment, 69 ignores most of the unwinding, and 99 is only the value returned by the deepest call before the four decrements on the way back.
95 option is correct.
Which method is called first by an applet program ?
Converting a primitive type data into its corresponding wrapper class object instance is called
Which methods are utilized to control the access to an object in multi-threaded programming ?
Which one of the following is correct ?
The Servlet Response interface enables a servlet to formulate a response for a client using the method __________.
In Java, when we implement an interface method, it must be declared as :
Match the following interfaces of Java. Servlet package :
| List - I | List - II |
| a. Servlet Config | i. Enables Servlets to log events |
| b. Servlet Context | ii. Read data from a client |
| c. Servlet Request | iii. Write data to a client |
| d. Servlet Response | iv. To get initialization parameters |
When one object reference variable is assigned to another object reference variable then
It is possible to define a class within a class termed as nested class. There are _____ types of nested classes.
Given the array of integers ‘array’ shown below :
| 13 | 7 | 27 | 2 | 18 | 33 | 9 | 11 | 22 | 8 |
What is the output of the following JAVA statements ?
int [ ] p = new int [10];
int [ ] q = new int [10];
for (int k = 0; k < 10; k ++)
p[k] = array [k];
q = p;
p[4] = 20;
System.out.println(array [4] + “:” + q[4]);
Arrange the following applet life cycles methods in sequence
A. start()
B. paint()
C. init()
D. stop()
Choose the correct answer from the options given below:
A java program that is embedded in HTML document and runs in the context of java capable browser is known as ______.
JAVA compiler translates source code into _______.
Which of the following statement(s) is/are correct regarding java programming?
I. Place a semicolon immediately after a method header
II. Define a method outside the braces of a class definition
The application in java, which is used for sending small applications to run at client side is __________.