Java & Python Debugging Exam Questions
Java & Python Debugging Exam Questions
OPTRA ‘2022
MCA&MSC(CS)
[Link]
Time:1hr
4. What will happen when you compile and run the following code?
public static void main(String[] args){
for(int i = 0; i < 10; i++){
if(i % 2 == 0)
continue;
[Link](i);
}
}
a)Code will print all even numbers between 0 to 10
b)Code will print all odd numbers between 0 to 10
c)Code will not compile
d)None
Answer: b) Code will print all odd numbers between 0 to 10
5. What is the output of the Java program with the Enhanced FOR loop
below?
public static void main(String[] args){
String countries[] = {"Orange", "Apple", "Grapes"};
int i=0;
for(String str: countries)
{
if(i<2)
;
else
break;
[Link](str + ",");
i++;
}
}
a)Orange, Apple, Grapes
b)Orange, Apple,
c)Orange,
d)None
Answer: b)Orange,Apple
a)Thread[5,main]
b) Thread[main,5]
c) Thread[main,0]
d) Thread[main,5,main]
Answer: d) Thread[main,5,main]
8. What is the length of the application box made by the following Java
program?
import [Link].*;
import [Link].*;
public class myapplet extends Applet
{
public void paint(Graphics g)
{
[Link]("A Simple Applet", 20, 20);
}
}
a) 20
b) 50
c) 100
d) System dependent
Answer: a) 20
11. What will be the output of the following Java program if input given is
‘abcqfghqbcd’?
class Input_Output
{
public static void main(String args[]) throws IOException
{
char c;
BufferedReader obj = new BufferedReader(new
InputStreamReader([Link]));
do
{
c = (char) [Link]();
[Link](c);
} while(c != 'q');
}
}
a) abcqfgh
b) abc
c) abcq
d) abcqfghq
Answer: c) abcq
interface calculate
{
void cal(int item);
}
class display implements calculate
{
int x;
public void cal(int item)
{
x = item * item;
}
}
class Main
{
public static void main(String args[])
{
display arr = new display();
arr.x = 0;
[Link](2);
[Link](arr.x);
}
}
A. 0
B. 2
C. 4
D. None of the mentioned
Answer: C. 4
[Link] is the correct way to inherit and implement the interface?
4+3%5
a) 7
b) 2
c) 4
d) 1
Answer: a
17. What will be the output of the following Python code?
i=1
while True:
if i%3 == 0:
break
print(i)
i+=1
a) 1 2 3
b) error
c) 1 2
d) none of the mentioned
Answer: b
18. What are the values of the following Python expressions?
2**(3**2)
(2**3)**2
2**3**2
a) 512, 64, 512
b) 512, 512, 512
c) 64, 512, 64
d) 64, 64, 64
Answer: a
19. What will be the output of the following Python code?
Answer: c
20. The following python program can work with ____ parameters.
def f(x):
def f1(*args, **kwargs):
print("Sanfoundry")
return x(*args, **kwargs)
return f1
a) any number of
b) 0
c) 1
d) 2
Answer: a
21. What will be the output of the following Python function?
min(max(False,-3,-4), 2,7)
a) -4
b) -3
c) 2
d) False
Answer: d
22. What will be the output of the following Python expression if x=56.236?
print("%.2f"%x)
a) 56.236
b) 56.23
c) 56.0000
d) 56.24
Answer: d
23. What will be the output of the following Python code?
x = 'abcd'
for i in x:
print([Link]())
a) a B C D
b) a b c d
c) error
d) A B C D
Answer: d
24. What will be the output of the following Python code snippet?
1. >>>"a"+"bc"
a) bc
b) abc
c) a
d) bca
Answer: b
26. What will be the output of the following Python code?
1. class tester:
2. def __init__(self, id):
3. [Link] = str(id)
4. id="224"
5.
6. >>>temp = tester(12)
7. >>>print([Link])
a) 12
b) 224
c) None
d) Error
Answer: a
27. What will be the output of the following Python program?
def foo(x):
x[0] = ['def']
x[1] = ['abc']
return id(x)
q = ['abc', 'def']
print(id(q) == foo(q))
a) Error
b) None
c) False
d) True
Answer: d
28. What will be the output of the following Python program?
z=set('abc')
[Link]('san')
[Link](set(['p', 'q']))
z
a) {‘a’, ‘c’, ‘c’, ‘p’, ‘q’, ‘s’, ‘a’, ‘n’}
b) {‘abc’, ‘p’, ‘q’, ‘san’}
c) {‘a’, ‘b’, ‘c’, ‘p’, ‘q’, ‘san’}
d) {‘a’, ‘b’, ‘c’, [‘p’, ‘q’], ‘san}
Answer: c
29. What will be the value of ‘result’ in following Python program?
list1 = [1,2,3,4]
list2 = [2,4,5,6]
list3 = [2,6,7,8]
result = list()
[Link](i for i in list1 if i not in (list2+list3) and i not in result)
[Link](i for i in list2 if i not in (list1+list3) and i not in result)
[Link](i for i in list3 if i not in (list1+list2) and i not in result)
a) [1, 3, 5, 7, 8]
b) [1, 7, 8]
c) [1, 2, 4, 7, 8]
d) error
Answer: a
30. What will be the output of the following Python code?
Answer: b