C++/ Java Interview Questions - GE

1. Find the error in the below code?
int j;
for(int i=0;i<14;i++) {
if(i<10) {
j = 2 + i;
}
System.out.println("j: " + j + " i: " + i);
}

a) Integer "j" is not initialized.
b) Nothing.
c) Cannot declare integer i inside the for-loop declaration.
d) The syntax of the "if" statement is incorrect.
e) Cannot print integer values without converting them to strings.

2. Which one of the following is a valid declaration of an applet?

a) Public class MyApplet extends java.applet.Applet {
b) Public Applet MyApplet {
c) Public class MyApplet extends applet implements Runnable {
d) Abstract class MyApplet extends java.applet.Applet {
e) Class MyApplet implements Applet {

3. What values of X will print all members of array “values”?
int values[] = {1,2,3,4,5,6,7,8};
for(int i=0;i< X; ++i)
System.out.println(values[i]);

a) 1 b) 7 c) 8 d) 9 e) None

4. When m1 (2) is invoked, m2 () throws an ArithmeticException and what does m1() returns?

public int m1(int x) {
int count=1;
try {
count += x;
count += m2(count);
count++;
}
catch(Exception e) { count -= x; }
return count; }

a) 1 b) 2 c) 3 d) 4
e) None

5. What is the output of the following program?
main(){
char a[4] ="GOOGLE";
cout<
a) 2
b) GOOGLE
c) Compiler error
d) Linkage error.

6. Given a binary search tree,print out the nodes of the tree according to post order traversal.
4
/ \
2 5
/ \
1 3
a)3,2,1,5,4. b)1,2,3,4,5. c)1,3,2,5,4. d)5,3,1,2,4

7. Which one of the following is the recursive travel technique?

a) depth first search b)sequential search c)breadth first search d)none.
Post your comment