Select the Option which is invalid about throws in Exception handling in Java

This section of our 1000+ Java MCQs focuses on exception handling of Java Programming Language.

1. When does Exceptions in Java arises in code sequence?
a) Run Time
b) Compilation Time
c) Can Occur Any Time
d) None of the mentioned
View Answer

Answer: a
Explanation: Exceptions in Java are run-time errors.

2. Which of these keywords is not a part of exception handling?
a) try
b) finally
c) thrown
d) catch
View Answer

Answer: c
Explanation: Exceptional handling is managed via 5 keywords – try, catch, throws, throw and finally.

3. Which of these keywords must be used to monitor for exceptions?
a) try
b) finally
c) throw
d) catch
View Answer

Answer: a
Explanation: None.

4. Which of these keywords must be used to handle the exception thrown by try block in some rational manner?
a) try
b) finally
c) throw
d) catch
View Answer

Answer: d
Explanation: If an exception occurs within the try block, it is thrown and cached by catch block for processing.

5. Which of these keywords is used to manually throw an exception?
a) try
b) finally
c) throw
d) catch
View Answer

Answer: c
Explanation: None.

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

  1.     class exception_handling 
  2.     {
  3.         public static void main(String args[]) 
  4.         {
  5.             try 
  6.             {
  7.                 System.out.print("Hello" + " " + 1 / 0);
  8.             }
  9.             catch(ArithmeticException e) 
  10.             {
  11.         	System.out.print("World");        	
  12.             }
  13.         }
  14.     }

a) Hello
b) World
c) HelloWorld
d) Hello World
View Answer

Answer: b
Explanation: System.ou.print() function first converts the whole parameters into a string and then prints, before “Hello” goes to output stream 1 / 0 error is encountered which is cached by catch block printing just “World”.
Output:

$ javac exception_handling.java
$ java exception_handling
World

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

  1.     class exception_handling 
  2.     {
  3.         public static void main(String args[]) 
  4.         {
  5.             try 
  6.            {
  7.                 int a, b;
  8.                 b = 0;
  9.                 a = 5 / b;
  10.                 System.out.print("A");
  11.             }
  12.             catch(ArithmeticException e) 
  13.             {
  14.         	System.out.print("B");        	
  15.             }
  16.         }
  17.     }

a) A
b) B
c) Compilation Error
d) Runtime Error
View Answer

Answer: b
Explanation: None.
Output:

$ javac exception_handling.java
$ java exception_handling
B

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

  1.     class exception_handling 
  2.     {
  3.         public static void main(String args[]) 
  4.         {
  5.             try 
  6.             {
  7.                 int a, b;
  8.                 b = 0;
  9.                 a = 5 / b;
  10.                 System.out.print("A");
  11.             }
  12.             catch(ArithmeticException e) 
  13.             {
  14.         	System.out.print("B");        	
  15.             }
  16.             finally 
  17.             {
  18.     	        System.out.print("C");
  19.             }
  20.         }
  21.     }

a) A
b) B
c) AC
d) BC
View Answer

Answer: d
Explanation: finally keyword is used to execute the code before try and catch block end.
Output:

$ javac exception_handling.java
$ java exception_handling
BC

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

  1.     class exception_handling 
  2.     {
  3.         public static void main(String args[]) 
  4.         {
  5.             try 
  6.             {
  7.                 int i, sum;
  8.                 sum = 10;
  9.                 for (i = -1; i < 3 ;++i)
  10.                     sum = (sum / i);
  11.             }
  12.             catch(ArithmeticException e) 
  13.             {
  14.         	System.out.print("0");        	
  15.             } 
  16.             System.out.print(sum);
  17.         }
  18.     }

a) 0
b) 05
c) Compilation Error
d) Runtime Error
View Answer

Answer: c
Explanation: Value of variable sum is printed outside of try block, sum is declared only in try block, outside try block it is undefined.
Output:

$ javac exception_handling.java
Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
	sum cannot be resolved to a variable

Sanfoundry Global Education & Learning Series – Java Programming Language.

Next Steps:

  • Get Free Certificate of Merit in Java Programming
  • Participate in Java Programming Certification Contest
  • Become a Top Ranker in Java Programming
  • Take Java Programming Tests
  • Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
  • Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

Select the Option which is invalid about throws in Exception handling in Java

Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & technical discussions at Telegram SanfoundryClasses.

Which is invalid about throws in exception handling in Java?

Which is invalid about throws in Exception handling in java? b. throws can be used to throw multiple exception at time.

What is invalid exception in Java?

The IllegalArgumentException is an unchecked exception in Java that is thrown to indicate an illegal or unsuitable argument passed to a method. It is one of the most common exceptions that occur in Java.

Which of these points will be invalid if superclass method does not throw an exception?

Rule 1: If the superclass method does not declare an exception, subclass overridden method cannot declare the checked exception.

Which of the following is not a valid exception class in Java?

1 Answer. The correct answer to the question “Which of the following is NOT a . NET Exception class” is, option (a). StackMemoryException.