22412 JAVA PROGRAMMING MCQ QB 1
Unit 4: Exception Handling and Multithreading
1. Which of the following are the most common run-time errors in Java programming.
i) Missing semicolons
ii) Dividing an integer by zero
iii) Converting invalid string to number
iv) Bad reference of objects
A) i and ii only
B) ii and iii only
C) iii and iv only
D) i and iv only
2. Which of the following are the most common compile time errors in Java programming.
i) Missing semicolons
ii) Use of undeclared variables
iii) Attempting to use a negative size for an array
iv) Bad reference of objects
A) i, ii and iii only
B) ii, iii and iv only
C) i, ii and iv only
D) All i, ii, iii and iv
3. The unexpected situations that may occur during program execution are
i) Running out of memory
ii) Resource allocation errors
iii) Inability to find a file
iv) Problems in network
A) i, ii and iii only
B) ii, iii and iv only
C) i, ii and iv only
D) All i, ii, iii and iv
4. The class at the top of the exception classes hierarchy is called ……………………
A) throwable
B) catchable
C) hierarchical
D) ArrayIndexOutofBounds
5. ………………… exception is thrown when an exceptional arithmetic condition has occurred.
A) Numerical
B) Arithmetic
C) Mathematical
D) All of the above
6. ……………………….. exception is caused when an applet tries to perform an action not allowed by the browser’s security setting.
A) Throwable
B) Restricted
C) Security
D) ArrayIndexOutofBounds
7. …………………….. an exception is thrown when an attempt is made to access an array element beyond the index of the array.
A) Throwable
B) Restricted
C) Security
D) ArrayIndexOutofBounds
8. You can implement exception-handling in your program by using which of the following keywords.
i) Try ii) NestTry iii) Catch iv) Finally
A) i, ii and iii only
B) ii, iii and iv only
C) i, iii and iv only
D) All i, ii, iii and iv
9. When a ……………………. block is defined, this is guaranteed to execute, regardless of whether or not an exception is thrown.
A) throw
B) catch
C) finally
D) try
10. The ……………………. statement is passed a single parameter, which is reference to the exception object thrown.
A) throw
B) catch
C) finally
D) try
11. Every try statement should be followed by at least one catch statement; otherwise …………………. will occur.
A) no execution
B) null
C) zero
D) compilation error
12. If an exception occurs within the …………………….. block, the appropriate exception-handler that is associated with the try block handles the exception.
A) throw
B) catch
C) finally
D) try
13) Exception classes are available in the ……………………package.
A) java.lang
B) java.awt
C) java.io
D) java.applet
14. …………………….. is caused by general I/O failures, such as inability to read from file.
A) I/O failure
B) I/O exception
C) I/O inability
D) I/O distortion
15. Consider the following try…….. catch block:
class TryCatch
{
public static void main(String args[ ])
{
try
{
double x=0.0;
throw(new Exception("Thrown"));
return;
}
catch(Exception e)
{
System.out.println("Exception caught");
return;
}
finally
{
System.out.println("finally");
}
}
}
What will be the output?
A) Exception caught
B) Exception caught finally
C) finally
D) Thrown
16. Consider the following code snippet:
...................
...................
try {
int x=0;
int y=50/x;
System.out.println("Division by zero");
}
catch(ArithmeticException e) {
System.out.println("catch block");
}
..................
..................
What will be the output?
A) Error.
B) Division by zero
C) Catch block
D) Division by zero Catch block
17. State whether the following statements are True or False.
i) A catch can have comma-separated multiple arguments.
ii) Throwing an Exception always causes program termination.
A) True, False
B) False, True
C) True, True
D) False, False
18. Java uses a keyword ………………… to preface a block of code that is likely to cause an error condition and ‘throw’ an exception.
A) throw
B) catch
C) finally
D) try
19. When an exception in a try block is generated, Java treats the multiple ………………. statements like cases in switch statements.
A) throw
B) catch
C) finally
D) try
20. The …………………. statement can be used to handle an exception that is not caught by any of the previous catch statements.
A) throw
B) catch
C) finally
D) try
21. What is multithreaded programming?
a) It’s a process in which two different processes run simultaneously
b) It’s a process in which two or more parts of same process run simultaneously
c) It’s a process in which many different process are able to access same information
d) It’s a process in which a single process can access information from many sources
22. Which of these are types of multitasking?
a) Process based
b) Thread based
c) Process and Thread based
d) None of the mentioned
23. Thread priority in Java is?
a) Integer
b) Float
c) double
d) long
24. What will happen if two thread of the same priority are called to be processed simultaneously?
a) Anyone will be executed first lexographically
b) Both of them will be executed simultaneously
c) None of them will be executed
d) It is dependent on the operating system
25. Which of these statements is incorrect?
a) By multithreading CPU idle time is minimized, and we can take maximum use of it
b) By multitasking CPU idle time is minimized, and we can take maximum use of it
c) Two thread in Java can have the same priority
d) A thread can exist only in two states, running and blocked
26. 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]
27. What is the priority 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) 4
b) 5
c) 0
d) 1
28. 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
Happy Learning!
Comments
Post a Comment
If you have any query, please let us know