NEW
Font size
WorksheetsTEST!
Total questions: 26
Worksheet time: 17mins
Which keyword ensures thread safety?
A. volatile
B. static
C. final
D. synchronized
Which method causes a thread to pause for a fixed time?
A. wait()
B. sleep()
C. stop()
D. pause()
Which method releases the lock?
A. sleep()
B. yield()
C. wait()
D. join()
. Can we restart a terminated thread?
A. Yes
B. No
C. Sometimes
D. Depends on JVM
Which class provides thread pool support?
A. Thread
B. Runnable
C. Executors
D. Collections
Which keyword ensures visibility between threads?
A. final
B. static
C. volatile
D. synchronized
Which exception is thrown when thread is interrupted?
A. IOException
B. InterruptedException
C. ThreadException
D. RuntimeException
Deadlock occurs when
A. Thread runs fast
B. Thread sleeps
C. Two threads wait for each other
D. CPU usage increases
class Test extends Thread {
public static void main(String[] args) {
Test t = new Test();
t.start();
t.start();
}
}
A. Runs twice
B. Compile error
C. Runtime exception
D. Deadlock
class Test {
public static void main(String[] args) throws Exception {
Thread t = new Thread();
t.start();
t.join();
System.out.print("End ");
}
}
A. End
B. No output
C. Compile error
D. Runtime error
class Test {
public static void main(String[] args) {
Thread.currentThread().join();
System.out.print("End ");
}
}
A. End
B. Compile error
C. Deadlock
D. Runtime exception
String s = "Java";
s.concat("World");
System.out.println(s);
A. JavaWorld
B. Java
C. Compile error
NONE
try {
int a = 10 / 0;
} catch (ArithmeticException e) {
System.out.println("Catch");
} finally {
System.out.println("Finally");
}
A. Catch
B. Finally
C. Catch Finally
D. Runtime error
Set set = new HashSet();
set.add(10);
set.add(10);
System.out.println(set.size());
A. 1
B. 2
C.0
D.NONE
String s1 = "Hello";
String s2 = new String("Hello");
System.out.print(s1 == s2);
false
true
none
System.out.print("A");
System.exit(0);
System.out.print("B");
A. A
B. AB
C. B
D. Compile Error
#include <stdio.h>
int main() {
printf("%d", printf("Hello"));
return 0;
}
A. Hello5
B. 5Hello
C. Hello
D. Compile error
#include <stdio.h>
int main() {
int a[] = {10, 20, 30};
int *p = a;
printf("%d", *(p + 1));
return 0;
}
A. 10
B. 20
C. 30
D. Garbage
#include <stdio.h>
void fun() {
static int x = 0;
x++;
printf("%d ", x);
}
int main() {
fun();
fun();
fun();
return 0;
}
A. 1 1 1
B. 1 2 3
C. 0 1 2
D. Garbage
#include <stdio.h>
#define SQR(x) x*x
int main() {
printf("%d", SQR(3+2));
return 0;
}
A. 25
B. 11
C. 13
D. Compile error
#include <stdio.h>
#include <string.h>
int main() {
char s[] = "Hello\0World";
printf("%d", strlen(s));
return 0;
}
A. 5
B. 10
C. 11
D. Compile error
#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. 3
B. 6
C. 9
D. 0
#include <stdio.h>
int main() {
int x = 0;
printf("%d", x && printf("Hello"));
return 0;
}
A. Hello0
B. 0
C. Hello1
D. Compile error
#include <stdio.h>
void fun(int arr[]) {
printf("%d", sizeof(arr));
}
int main() {
int a[10];
fun(a);
return 0;
}
A. 40
B. 10
C. 4
D. Compile error
#include <stdio.h>
int main() {
int a[2][3] = {{1,2,3},{4,5,6}};
printf("%d", a[1][2]);
return 0;
}
A. 3
B. 4
C. 5
D. 6
#include <stdio.h>
int main() {
int a[5] = {1,2};
printf("%d", a[3]);
return 0;
}
A. 1
B. 2
C. 0
D. Garbage
