Professional Documents
Culture Documents
{
String str = "a";
void A()
{
try
{
str +="b";
B();
}
catch (Exception e)
{
str += "c";
}
}
str += "f";
void display()
{
System.out.println(str);
}
Answer: abdec
Say that methodA calls methodB, and methodB calls methodC. MethodC might throw a
NumberFormatException. Can the program be written so that methodA handles the exception?
d. Yes, if the headers for methodC and methodB say ...throws NumberFormatException
Answer: D. Yes, if the headers for methodC and methodB say ...throws NumberFormatException
a. Class Exception.
class Main {
int x = 0;
int y = 10;
int z = y/x;
a.Class
b.Interface
c.Abstract class
d.Other
Answer: A. Class
a.java.lang
b.java.util
c.java.io
d.java
Answer: A. java.lang
a.catch
b.throw
c.throws
d.raise
Answer: D. raise
Which method of the "Exception" class prints a list of methods that were called before the exception
was thrown? Please select the correct option "A, B, C, D, or E"
A. printErrors()
B. getMessage()
C. printStackTrace()
D. traceStack()
E. toString()
Answer: C. printStackTrace()
String x = null;
giveMeAString(x);
System.out.println(x);
y = "GeeksQuiz";
A. GeeksQuiz
B. Null
C. Compiler error
D. Exception
Answer: B. null
What is the output of this main() method? Put the letters into the answer box provided with no spaces
between (i.e. ABCEDFG)
int value;
System.out.print("@");
v = getRemoteId();
System.out.print(v);
System.out.print("E");
v = getStudentCount();
System.out.print(v);
System.out.print("F");
v = getMonitorCount();
System.out.print("W");
return 3;
return 2;
return 6;
Answer: @3E6FW
It refers to the part of function heading that specifies an input for the function to perform its task.
A. Global variable
B. Function arguments or function parameters
C. Function statements
D. Function heading
Answer: B. Function arguments or function parameters
A. function declaration
B. function call
C. function definition
D. function name
It is a statement that tells the compiler about a function's name, return type, and parameters
A. function definition
B. function call
C. function declaration
D. function name
A. function definition
B. function call
C. function declaration
D. function name
This method copies the actual value of an argument into the formal parameter of the function.
A. Call by value
B. Call by reference
C. Call by pointer
To call the function startCall() with the number 4432 and 3 retries what would you write in the main()
function? Remember to put a ; at the end of the statement.
void startCall(int number, int retries)
// code is hidden
class Test
str.toUpperCase();
str += "forgeeks";
System.out.println(string);
(A) eksforgeekss
(B) eksforgeeks
(C) EKSforgeekss
(D) EKSforgeeks
//precondition: x>=0
System.out.print(x % 10);
if (x % 10 != 0)
demo(x/10);
System.out.print(x%10);
(A) 1441
(B) 3443
(C) 12344321
(D) 43211234
Explanation: In the above code, first print statement is executed and prints the value obtained after
performing modulus of 10 and the recursively another function is called with the value divide by 10. And
after the return of the function, it prints the values again.
demo(1234)
Thus answer is D.
square(1) = 1
square(N) = square(N-1) + 2N -1
Assume the definition has been implemented correctly. How many activations will there be on the
activation chain if main() calls square(5)?
A. 1
B. 3
C. 5
D. 6
Answer: C. 5
Consider the following recursive C function. If get(6) function is being called in main() then how many
times will the get() function be invoked before returning to the main()?
if (n < 1) return;
get(n-1);
get(n-3);
printf("%d", n);
(A) 15
(B) 25
(C) 35
(D) 45
Answer: (B) 25
int f(int j)
int k;
if (i == j)
printf(“something”);
k = f(i);
return 0;
else return 0;
(B) The function prints the string something for all values of j.
(D) The function will exhaust the runtime stack or run into an infinite loop when j = 50
Answer: (D) The function will exhaust the runtime stack or run into an infinite loop when j = 50
Explanation: When j is 50, the function would call itself again and again as neither i nor j is changed inside
the recursion.
int x=1, k;
if (n==1) return x;
return x;
(A) 0
(B) 26
(C) 51
(D) 71
Answer: (C) 51
Explanation:
= 1 + 2*[fun(1)*fun(4) + fun(2)*fun(3)]
Substituting fun(1) = 1
= 1 + 2*[fun(4) + fun(2)*fun(3)]
= 1 + 2*1*5 + 2*2 = 15
int f(int n)
static int i = 1;
if (n >= 5)
return n;
n = n+i;
i++;
return f(n);
(A) 5
(B) 6
(C) 7
(D) 8
Answer: (C) 7
if (y == 0) return 0;
if (b == 0) return 1;
(A) x*y
(B) x+x*y
(C) xy
(D) yx
Answer: (C) xy
void count(int n)
static int d = 1;
d++;
if(n > 1) count(n-1);
int main()
count(3);
(A) 3 1 2 2 1 3 4 4 4
(B) 3 1 2 1 1 1 2 2 2
(C) 3 1 2 2 1 3 4
(D) 3 1 2 1 1 1 2
Answer: (A) 3 1 2 2 1 3 4 4 4
Explanation:
So series will be A.
int f (int n) {
if (n <= 1) return 1;
Assuming that arbitrarily large integers can be passed as a parameter to the function, consider the
following statements.
iii. The function f does not terminate for finitely many different values of n ≥ 1.
iv. The function f does not terminate for infinitely many different values of n ≥ 1.
Explanation: The function terminates for all values having a factor of 2 {(2.x)2==0}
And any number with a factor of 5 and 2, there are infinite recursions possible.
Consider the following recursive function fun(x, y). What is the value of fun(4, 3)
if (x == 0)
return y;
A. 13
B. 12
C. 9
D. 10
Answer: A. 13