wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

programming quiz

Total questions: 25

Worksheet time: 25mins

Name
Class
Date
1.

public class A     

{  public static void main(String args[])  

  {  //\u000d System.out.println("hello");  

           }  }  

a)

Hello

b)

hello

c)

HELLO

d)

Error

e)

\u000dhello

2.

What will be the output of the following code ?

public class _C   {  

private static int $;  

public static void main(String main[])   {  

String a_b;  

System.out.print($);  

System.out.print(a_b);  

}   }  

a)

Compiler error at line 1.

b)

Compiler error at line 2.

c)

Compiler error at line 4.

d)

Compiler error at line 5.

e)

Compiler error at line 8.

3.

 What is the output for this code in python?

      a, b* = 1, 2, 3

    print(a, b)

a)

1 (2, 3)

b)

1 [2, 3]

c)

1 ,2 3

d)

1 {2, 3}

4.

What is the output for this code in python?

     a = []

     print(not a)

a)

False

b)

0

c)

True

d)

1

e)

Null

5.

What will be the output of the following Java program?

class Output

{

public static void main(String args[])

{int arr[] = {1, 2, 3, 4, 5};

for ( int i = 0; i < arr.length - 2; ++i)

System.out.println(arr[i] + " ");}

}

a)
123
b)

012

c)

345

d)

234

6.

 What will be the output of the following Java code?

class output

{

public static void main(String args[])

{String c = "Hello i love java";

boolean var;

var = c.startsWith("hello");

System.out.println(var);

}}

a)
False
b)

True

c)

0

d)

1

7.

Which of the following declaration is not supported by C language?

a)

String str;

b)

char *str;

c)

float str = 3e2;

d)

Both “String str;” and “float str = 3e2;”  

8.

What will be the output of the following Python code snippet?

def example(a):

a = a + '2'

a = a*2

return a

>>>example("hello")

a)

indentation Error

b)

cannot perform mathematical operation on strings

c)

hello2

d)

hello2hello2

9.

When an expression consists of int, double, long, float, then the entire expression will get promoted into a data type that is:

a)

float

b)

double

c)

int

d)

long

10.

What is the output for the following code?

a = [1,2,3,4,5]

a[2] = 8

print(a)

a)
[1,2,8,4,5]
b)

[1,8,3,4,5]

c)

[1,2,3,8,5]

d)

[1,2,8,5,3]

11.

Which one of the following is a loop construct that will always be executed once?

a)

for

b)

while

c)

switch

d)

do while

12.

Which function is used to read a line of text including spaces from the user in C?

a)

scanf()

b)

getc()

c)

fgets()

d)

All of the above

13.

main()

{ int a = 1, b = 2, c = 3;

printf("%d", a + = (a + = 3, 5, a))

}

What will be the output for the following code?

a)
8
b)

2

c)

5

d)

1

14.

What is meant by ‘a’ in the following C operation?

fp = fopen("Random.txt", "a");

a)

Attach

b)

Append

c)

Apprehend

d)

Add

15.

What will be the output of the following Python code?

  x = 'abcd'

for i in range(­­­­len(x)):

print(i)

a)
0123
b)

3210

c)

1234

d)

2345

16.

Identify the output for the following python code?

a = ["apple", "banana", "cherry"]

a.remove("banana")

print(a)

a)

['apple', 'cherry']

b)

['banana','cherry']

c)

['cherry','apple']

d)

['cherry','banana']

17.
  1. What will be print on the console?

  2. import java.util.Arrays;  

  3. public class SplitString  

  4. {  public static void main(String args[])   

  5. {  String str="Java|Python|Hadoop";  

  6. String[] array = str.split("\\|");  

  7. System.out.println(Arrays.toString(array));  

  8. }  } 

a)
  1. [Java\\ Python\\ Hadoop]

b)
  1. [Java|Python|Hadoop]

c)
  1. [Java\\|Python\\|Hadoop]

d)
  1. [Java, Python, Hadoop]

18.

What is the value of the expression 7%3 in java?

a)

1

b)

2

c)

3

d)

0

19.

Which package in java contains classes for event handling?

a)

java.util

b)

java.swing

c)

java.awt.event

d)

java.io

20.

Which of the following is not a valid identifier for a java variable?

a)

my_var

b)

_myVar

c)

3rdVar

d)

$var

21.

Which of the following data types in python is used to store key-value pairs?

a)

Dictionary

b)

List

c)

Tuple

d)

Set

22.

What will be the output for the following python code snippet?

d1 = {"john" : 40 ,"peter" : 45}

d2 = {"john" : 466 ,"peter" : 45}

d1 > d2

a)

True

b)

False

c)

Error

d)

None

23.

What is the output for the following python code?

Suppose d={"john" : 40 , "peter" : 45} , to delete the entry for "john" what command do we use?

a)

d.delete("john" : 40)

b)

d.delete("john")

c)

del d["john"]

d)

del d["john" : 4]

24.

What will be the output?

class One{

final int a = 15;}

class Two extends One

{ final int a = 20;

}

public class Test extends Two

{ final int a = 30;

public static void main(String args[]) {

Test t = new One();

System.out.print(t. a);}

}

a)

15

b)

20

c)

Compiler error

d)

None of these

25.

What will be the output of the following python function?

min ( max ( False , -3 , -4 ) , 2 , 7 )

a)

2

b)

False

c)

-3

d)

-4