wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

TEST!

Total questions: 26

Worksheet time: 17mins

Name
Class
Date
1.

Which keyword ensures thread safety?

a)

A. volatile

b)

B. static

c)

C. final

d)

D. synchronized

2.

Which method causes a thread to pause for a fixed time?

a)

A. wait()

b)

B. sleep()

c)

C. stop()

d)

D. pause()

3.

Which method releases the lock?

a)

A. sleep()

b)

B. yield()

c)

C. wait()

d)

D. join()

4.

. Can we restart a terminated thread?

a)

A. Yes

b)

B. No

c)

C. Sometimes

d)

D. Depends on JVM

5.

Which class provides thread pool support?

a)

A. Thread

b)

B. Runnable

c)

C. Executors

d)

D. Collections

6.

Which keyword ensures visibility between threads?

a)

A. final

b)

B. static

c)

C. volatile

d)

D. synchronized

7.

Which exception is thrown when thread is interrupted?

a)

A. IOException

b)

B. InterruptedException

c)

C. ThreadException

d)

D. RuntimeException

8.

Deadlock occurs when

a)

A. Thread runs fast

b)

B. Thread sleeps

c)

C. Two threads wait for each other

d)

D. CPU usage increases

9.

class Test extends Thread {

public static void main(String[] args) {

Test t = new Test();

t.start();

t.start();

}

}

a)

A. Runs twice

b)

B. Compile error

c)

C. Runtime exception

d)

D. Deadlock

10.

class Test {

public static void main(String[] args) throws Exception {

Thread t = new Thread();

t.start();

t.join();

System.out.print("End ");

}

}

a)

A. End

b)

B. No output

c)

C. Compile error

d)

D. Runtime error

11.

class Test {

public static void main(String[] args) {

Thread.currentThread().join();

System.out.print("End ");

}

}

a)

A. End

b)

B. Compile error

c)

C. Deadlock

d)

D. Runtime exception

12.

String s = "Java";

s.concat("World");

System.out.println(s);

a)

A. JavaWorld

b)

B. Java

c)

C. Compile error

d)

NONE

13.

try {

int a = 10 / 0;

} catch (ArithmeticException e) {

System.out.println("Catch");

} finally {

System.out.println("Finally");

}

a)

A. Catch

b)

B. Finally

c)

C. Catch Finally

d)

D. Runtime error

14.

Set set = new HashSet();

set.add(10);

set.add(10);

System.out.println(set.size());

a)

A. 1

b)

B. 2

c)

C.0

d)

D.NONE

15.

String s1 = "Hello";

String s2 = new String("Hello");

System.out.print(s1 == s2);

a)

false

b)

true

c)

none

16.

System.out.print("A");

System.exit(0);

System.out.print("B");

a)

A. A

b)

B. AB

c)

C. B

d)

D. Compile Error

17.

#include <stdio.h>

int main() {

printf("%d", printf("Hello"));

return 0;

}

a)

A. Hello5

b)

B. 5Hello

c)

C. Hello

d)

D. Compile error

18.

#include <stdio.h>

int main() {

int a[] = {10, 20, 30};

int *p = a;

printf("%d", *(p + 1));

return 0;

}

a)

A. 10

b)

B. 20

c)

C. 30

d)

D. Garbage

19.

#include <stdio.h>

void fun() {

static int x = 0;

x++;

printf("%d ", x);

}

int main() {

fun();

fun();

fun();

return 0;

}

a)

A. 1 1 1

b)

B. 1 2 3

c)

C. 0 1 2

d)

D. Garbage

20.

#include <stdio.h>

#define SQR(x) x*x

int main() {

printf("%d", SQR(3+2));

return 0;

}

a)

A. 25

b)

B. 11

c)

C. 13

d)

D. Compile error

21.

#include <stdio.h>

#include <string.h>

int main() {

char s[] = "Hello\0World";

printf("%d", strlen(s));

return 0;

}

a)

A. 5

b)

B. 10

c)

C. 11

d)

D. Compile error

22.

#include <stdio.h>

int fun(int n) {

if(n == 0)

return 0;

return n + fun(n - 1);

}

int main() {

printf("%d", fun(3));

return 0;

}

a)

A. 3

b)

B. 6

c)

C. 9

d)

D. 0

23.

#include <stdio.h>

int main() {

int x = 0;

printf("%d", x && printf("Hello"));

return 0;

}

a)

A. Hello0

b)

B. 0

c)

C. Hello1

d)

D. Compile error

24.

#include <stdio.h>

void fun(int arr[]) {

printf("%d", sizeof(arr));

}

int main() {

int a[10];

fun(a);

return 0;

}

a)

A. 40

b)

B. 10

c)

C. 4

d)

D. Compile error

25.

#include <stdio.h>

int main() {

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

printf("%d", a[1][2]);

return 0;

}

a)

A. 3

b)

B. 4

c)

C. 5

d)

D. 6

26.

#include <stdio.h>

int main() {

int a[5] = {1,2};

printf("%d", a[3]);

return 0;

}

a)

A. 1

b)

B. 2

c)

C. 0

d)

D. Garbage