Batch15 Multithreading and Exception
Batch15 Multithreading and Exception
Given:
12. try {
15. f = 0;
16. } finally {
17. System.out.println(f);
18. }
19. }
21. parse("invalid");
22. }
Your Answer:
0.0
Compilation fails.
2.
1 point
Given:
12. try {
15. }
17. }
22. }
Your Answer:
test end
Compilation fails.
3.
1 point
Given:
33. try {
36. System.out.print("a");
38. System.out.print("b");
39. } finally {
40. System.out.print("c");
41. }
Your Answer:
ac
4.
1 point
Given:
32. try {
36. } finally {
38. }
Under which three circumstances will the code on line 37 be executed? (Choose
three.)
Your Answer:
5.
1 point
Given:
12. try {
15. }
17. }
21. }
Your Answer:
null
finally
null finally
Compilation fails.
finally exception
6.
1 point
Given:
14. }
19. }
Your Answer:
end
Compilation fails.
exception end
7.
1 point
Given:
2. class A {
6. }
7. }
11. }
12. }
Your Answer:
Compilation succeeds.
8.
1 point
Given:
13. }
16. }
19. }
Your Answer:
9.
1 point
Given:
14. }
Which exception or error will be thrown when a programmer attempts to run this
code?
Your Answer:
java.lang.StackOverflowError
java.lang.IllegalStateException
java.lang.ArrayIndexOutOfBoundsException
. java.lang.ExceptionInInitializerError
10.
1 point
Given:
11. class A {
15. super.process();
16. System.out.print("B,");
18. }
22. }
Your Answer:
Exception
A,B,Exception
11.
1 point
Your Answer:
Multiple catch statements can catch the same class of exception more than once.
12.
1 point
Your Answer:
Run Time
Compilation Time
13.
1 point
class TryCatch
try
double x=0.0;
throw(new Exception("Thrown"));
return;
catch(Exception e)
System.out.println("Exception caught");
return;
finally
System.out.println("finally");
Your Answer:
Exception caught
finally
Thrown
14.
1 point
...................
...................
try {
int x=0;
int y=50/x;
System.out.println("Division by zero");
catch(ArithmeticException e) {
System.out.println("catch block");
..................
..................
Your Answer:
Error.
Division by zero
Catch block
15.
1 point
Your Answer:
True, False
False, True
True, True
False, False
16.
1 point
Your Answer:
It’s a process in which two or more parts of same process run simultaneously
It’s a process in which many different process are able to access same information
It’s a process in which a single process can access information from many sources
17.
1 point
class multi_programing {
Thread t = Thread.currentThread();
System.out.println(t);
Your Answer:
18.
1 point
Thread t;
String name;
newthread(String threadname) {
name = threadname;
t = new Thread(this,name);
t.start();
class multithreaded_programing{
try
obj1.t.wait();
System.out.print(obj1.t.isAlive());
catch(Exception e)
Your Answer:
True
false
19.
1 point
Thread t;
newthread(){
t.start();
t.setPriority(Thread.MAX_PRIORITY);
System.out.println(t);
class multithreaded_programing{
new newthread();
Your Answer:
Thread[New Thread,0,main]
Thread[New Thread,1,main]
Thread[New Thread,5,main]
Thread[New Thread,10,main]
20.
1 point
try{
Thread.sleep(100);
System.out.println(Thread.currentThread().getName());
} catch (InterruptedException e) {
A a new A(); =
t.start();
t.join();
t1.start();
Your Answer:
A.A A A A B B B B
B.A B A B A B A B
21.
1 point
============
threadE.start();
Your Answer:
22.
1 point
super(name);
if(Thread.currentThread().isDaemon()) {
else
t1.setDaemon(true);
t1.start();
t2.start();
t3.setDaemon(true);
t3.start();
Your Answer:
t1 is Daemon thread
t3 is Daemon thread
t2 is User threa
t3 is Daemon thread
t2 is User thread
t1 is Daemon thread
t2 is User thread
23.
1 point
System.out.println("Run");
class Myclass {
t1.start();
System.out.println("Main");
Your Answer:
Run
Main
Run Main
24.
1 point
class Base {
System.out.println("Base::show() called");
System.out.println("Derived::show() called");
class Main {
b.show();
Your Answer:
Base::show() called
Derived::show() called
Compiler Error
Runtime Error
25.
1 point
Which of the following statements is correct with respect to the above code?
Your Answer:
26.
1 point
newthread() {
super("My Thread");
start();
System.out.println(this);
class multithreaded_programing{
new newthread();
Your Answer:
My Thread
Thread[My Thread,5,main].
Compilation Error
Runtime Error
27.
1 point
Thread t;
newthread(){
t.start();
try
t.join()
System.out.println(t.getName());
catch(Exception e)
System.out.print("Exception");
class multithreaded_programing {
new newthread();
Your Answer:
a.My Thread
b.Thread[My Thread,5,main].
c.Exception
d.Runtime Error
28.
1 point
============
t.start();
System.out.print("one. ");
t.start();
System.out.print("two. ");
System.out.print("Thread ");
Your Answer:
Compilation fails
29.
1 point
class Test{
printAll(args);
System.out.println(lines[i]);
Thread.currentThread().sleep(1000);
Your Answer:
Each String in the array lines will output, and there is no guarantee there will be a
pause because currentThread() may not retrieve this thread.
Each String in the array lines will output, with no pause in between because this
method is not executed in a Thread.
Each String in the array lines will output, with a 1-second pause.
30.
1 point
System.out.print("Child ");
throws InterruptedException {
t.start();
t.join();
System.out.print("Main ");
Your Answer:
Main Child
Child Main
Main Main
Child Child
31.
1 point
try {
mt.join();
} catch(InterruptedException ie) {}
System.out.print("Child ");
throws InterruptedException {
MyThread.mt = Thread.currentThread();
t.start();
Thread.sleep(1000);
System.out.print("Main ");
Your Answer:
Main Child
Child Main
Main Main
Child Child
32.
1 point
Your Answer:
Exactly 1 second
Minimum 1 second
Maximum 1 second
33.
1 point
If a thread wants to pause its execution to give the chance for remaining threads of
the same priority then which method should be called?
Your Answer:
yield() method
join() method
sleep() method
All of these
34.
1 point
m1();
Integer.parseInt("two");
m2();
System.out.println(9/0);
Thread.sleep(1000);
Your Answer:
main()
m1()
m2()
Compiled Successfully
35.
1 point
throws InterruptedException {
m1();
throws InterruptedException {
m2();
throws InterruptedException {
Thread.sleep(1000);
Your Answer:
main()
m1()
m2()
Compiled Successfully
36.
1 point
Your Answer:
Compile-time error
Exception
No output
None of these
37.
1 point
2. Thread()
3. Thread(int priority)
4. Thread(Runnable r, ThreadGroup g)
Your Answer:
1 and 3
2 and 4
1 and 2
2 and 5
38.
1 point
MyThread() {
System.out.print(" MyThread");
System.out.print(" bar");
System.out.println(" baz");
System.out.println(" foo");
};
t.start();
Your Answer:
foo
MyThread foo
MyThread bar
foo bar
39.
1 point
t.start();
System.out.print("one. ");
t.start();
System.out.print("two. ");
System.out.print("Thread ");
Your Answer:
Compilation fails
40.
1 point
int x = 0, y = 0;
t1.start();
t2.start();
Your Answer:
Logout