PG and Research Department of Computer Science
OPTRA ‘2022
MCA&MSC(CS)
Max.Marks:30
Time:1hr
Debugging on JAVA & PYTHON
1. Find the output of the following program.
public class Solution{
public static void main(String[] args){
short x = 10;
x = x * 5;
System.out.print(x);
}
}
a)50 b) 60 c) compile time d) exception
Answer: c) compile time
2. Identify the output of the following program.
Public class Test{
Public static void main(String argos[]){
String str1 = “one”;
String str2 = “two”;
System.out.println(str1.concat(str2));
}
}
One b) two c)onetwo d) twoone
Answer:c)onetwo
3. What will happen when you compile and run the following code?
public static void main(String[] args){
int i = 0;
for(i = 100; i >= 0; i -= 10 ){
System.out.print(i + ", ");
}
}
a)100, 90, 80, 70, 60, 50, 40, 20, 10, 0,
b)100, 90, 80, 70, 60, 50, 40, 20, 10,
c)90, 80, 70, 60, 50, 40, 20, 10, 0,
d)None of the above
Answer: a)100, 90, 80, 70, 60, 50, 40, 20, 10, 0,
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;
System.out.println(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;
System.out.print(str + ",");
i++;
}
}
a)Orange, Apple, Grapes
b)Orange, Apple,
c)Orange,
d)None
Answer: b)Orange,Apple
6. What will be the output of the following Java code?
class multithreaded_programing
{
public static void main(String args[])
{
Thread t = Thread.currentThread();
System.out.println(t);
}
}
a)Thread[5,main]
b) Thread[main,5]
c) Thread[main,0]
d) Thread[main,5,main]
Answer: d) Thread[main,5,main]
7. What is the name of the thread in the following Java Program?
class multithreaded_programing
{
public static void main(String args[])
{
Thread t = Thread.currentThread();
System.out.println(t);
}
}
a) main
b) Thread
c) System
d) None of the mentioned
Answer: a) main
8. What is the length of the application box made by the following Java
program?
import java.awt.*;
import java.applet.*;
public class myapplet extends Applet
{
public void paint(Graphics g)
{
g.drawString("A Simple Applet", 20, 20);
}
}
a) 20
b) 50
c) 100
d) System dependent
Answer: a) 20
9. Which of these modifiers can be used for a variable so that it can be
accessed from any thread or parts of a program?
a) transient
b) volatile
c) global
d) No modifier is needed
Answer: b) volatile
10. What will be the output of the following Java program?
class exception_handling
{
public static void main(String args[])
{
try
{
System.out.print("Hello" + " " + 1 / 0);
}
catch(ArithmeticException e)
{
System.out.print("World");
}
}
}
a) Hello
b) World
c) HelloWorld
d) Hello World
Answer: b) World
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(System.in));
do
{
c = (char) obj.read();
System.out.print(c);
} while(c != 'q');
}
}
a) abcqfgh
b) abc
c) abcq
d) abcqfghq
Answer: c) abcq
12. What will be the output of the following Java program?
class output
{
public static void main(String args[])
{
StringBuffer c = new StringBuffer("Hello");
System.out.println(c.length());
}
}
a) 4
b) 5
c) 6
d) 7
Answer: b) 5
13. Choose correct declaration and importing of packages in Java.
A)
package SOMEPACKAGE;
import PACKAGE_N.*;
B)
import PACKAGE_N.*;
package SOMEPACKAGE;
C)
import PACKAGE_M.*;
package SOMEPACKAGE;
import PACKAGE_N.*;
D) All the above
Answer : a) package SOMEPACKAGE;
import PACKAGE_N.*;
14. What is the output of this program?
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;
arr.cal(2);
System.out.print(arr.x);
}
}
A. 0
B. 2
C. 4
D. None of the mentioned
Answer: C. 4
15.Which is the correct way to inherit and implement the interface?
a)class Cat implements IAnimal{}
b)class Cat import IAnimal{}
c)class Cat extends IAnimal{}
d)None is correct
Answer: a) class Cat implements IAnimal{}
16. What will be the value of the following Python expression?
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?
l=[1, 0, 2, 0, 'hello', '', []]
list(filter(bool, l))
a) [1, 0, 2, ‘hello’, ”, []]
b) Error
c) [1, 2, ‘hello’]
d) [1, 0, 2, 0, ‘hello’, ”, []]
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(i.upper())
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?
for i in [1, 2, 3, 4][::-1]:
print (i)
a) 4 3 2 1
b) error
c) 1 2 3 4
d) none of the mentioned
View Answer
Answer: a
Explanation: [::-1] reverses the list.
25. What will be the output of the following Python statement?
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. self.id = str(id)
4. id="224"
5.
6. >>>temp = tester(12)
7. >>>print(temp.id)
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')
z.add('san')
z.update(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()
result.extend(i for i in list1 if i not in (list2+list3) and i not in result)
result.extend(i for i in list2 if i not in (list1+list3) and i not in result)
result.extend(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?
print('*', "abcde".center(6), '*', sep='')
a) * abcde *
b) *abcde *
c) * abcde*
d) * abcde *
Answer: b
Signature of the H.O.D