Java  Exception Handling Mcq, java mcq




1. When does exception code in Java occur in sequence?

a) run time
B) compile time
C) can happen at any time
d) none of the mentioned
Answer: A
Explanation: Exceptions in Java are run-time errors.

2. Which of these keywords is not part of exception handling?
A try
B) in the end
C) thrown
D) hold
Answer: C
Explanation: Exceptional handling is managed through 5 keywords - try, catch, throw, throw and finally.

3. Which of these keywords should be used to monitor exceptions?
A try
B) in the end
C) throwing
D) hold
Answer: A
Explanation: None.

4. Which of these keywords should be used to handle an exceptionally thrown exception?
A)\try
B) in the end
C) throwing
D) hold
Answer: D
Explanation: If an exception occurs within the attempt block, it is thrown and cached by the catch block for processing.


5. Which of these keywords is used to manually throw an exception?
A) try
B) in the end
C) throwing
D) hold
Answer: C
Explanation: None.

6. What will be the output of the following Java programs?
Class exception_handling
{
public static void main (String [] args[])
{
try
{
System.out.print ("Hello" + "" + 1/0);
}
Catch (arithmetic exception)
{
System.out.print ("world");
}
}
}
a hello
b) world
C) Helloworld
D) Hello World
Answer: B
Explanation: The System.out.print () function first converts the entire parameters into a string and then prints, before the "hello" output stream goes to the 1/0 error, printing the block holding the "world". Is cached by
Output: $ javac exception_handling.java $ java exception_handling world

7. What will be the output of the following Java program?

Class exception_handling
{
public static void main (String [] args[])
{
try
{
int a, b;
B = 0;
a = 5 / b;
System.out.print ('A');
}
Catch (arithmetic exception)
{
System.out.print ("B");
}
}
}
A) a
B) b
C) compilation error
D) runtime error
Answer: B
Explanation: None.
Output: $ javac exception_handling.java $ java exception_handling b

8. What will be the output of the following Java program?
Class exception_handling
{
public static void main (String [] args[])
{
try
{
int a, b;
B = 0;
a = 5 / b;
System.out.print ('A');
}
Catch (arithmetic exception)
{
System.out.print ("B");
}
After all

{
System.out.print ('C');
}
}
}
A) a
B) b
c) AC
d) BC
Answer: D
Explanation: The keyword is used to execute the code and hold the block end before finally executing the code.
Output: $ javac exception_handling.java $ java exception_handling BC

9. Which of the following keywords is used to throw exceptions manually?
A) at the end
B) try
C) throwing
D) hold
Answer: C
Explanation: The "throw" keyword is used to manually throw exceptions in Java programs. User defined exceptions can also be thrown.

10. Which of the following classes can catch all exceptions that cannot be caught?
A) Runtime exception
b) error
c) exception
d) Parent Exception
Answer: B
Explanation: Runtime errors typically cannot be detected. The error class is used to catch such errors / exceptions.

11. Which of the following is a super class of all types of exception classes?
a) CATABLE
b) RuntimeException
C string
D) Throwable
Answer: D
Explanation: The Throbable is created in the class and all exception types are subclasses of this class. This is the super class of all exceptions.

12. Which of the following operators is used to generate an instance of an exception that can be thrown using a throw?
a) thrown
b) allotted
c) Mallok
D) new
Answer: D
Explanation: The new operator is used to create an instance of an exception. The exception may contain a parameter in the form of a string or may not contain a parameter.

13. Which of the following keywords is used by calling a function to handle an exception called a function?
a) throws
B) throw
C) try
D) hold
Answer: A
Explanation: A method specifies the behavior of being able to generate an exception. By exception throws the method's call guard's declaration method.

14. Which of the following uses an exception when a catch is not used?
A) at the end
b) throwing handler
C) default handler
d) Java run time system
Answer: C
Explanation: The default handler is used to handle all exceptions if a catch is not used to handle exceptions. The end is called in any case.

15. Which part of the code is executed or not, is the exception caught or not?
A) at the end
B) try
C) hold
D) throw
Answer: A
Explanation: Finally the code is blocked, regardless of whether the exception is caught or not. File closure, database connection closure, etc. are usually done at the end.

16. Which of the following items must be corrected by the thrown statement?
a) Must be assigned to string type
b) must be assigned to the exception type
C) must be assigned to threadable type
d) must be assigned to type error
Answer: C
Explanation: Throwable statement throwing sum
Previous Post Next Post