Java Multiple Choice Questions & Answers on Exceptions Types for Freshers

1. Which of these is a super class of all exceptional type classes?

a) String
b) RuntimeExceptions
c) Throwable
d) Cachable
Answer: c

Explanation: All the exception types are subclasses of the built in class Throwable.
2. Which of these class is related to all the exceptions that can be caught by using catch?

a) Error
b) Exception
c) RuntimeExecption
d) All of the mentioned
Answer: b

Explanation: Error class is related to java run time error that can’t be caught usually, RuntimeExecption is subclass of Exception class which contains all the exceptions that can be caught.
3. Which of these class is related to all the exceptions that cannot be caught?

a) Error
b) Exception
c) RuntimeExecption
d) All of the mentioned
Answer: a

Explanation: Error class is related to java run time error that can’t be caught usually, RuntimeExecption is subclass of Exception class which contains all the exceptions that can be caught.
4. Which of these handles the exception when no catch is used?

a) Default handler
b) finally
c) throw handler
d) Java run time system
Answer: a
5. Which of these keywords is used to manually throw an exception?

a) try
b) finally
c) throw
d) catch
Answer: c
6. What is the output of this program?
  1.     class exception_handling {
  2.         public static void main(String args[]) {
  3.             try {
  4.                 System.out.print("Hello" + " " + 1 / 0);
  5.             }
  6.             finally {
  7.          System.out.print("World");         
  8.             }
  9.         }
  10.     }
a) Hello
b) World
c) Compilation Error
d) First Exception then World
Answer: d
7. What is the output of this program?
  1.     class exception_handling {
  2.         public static void main(String args[]) {
  3.             try {
  4.                 int a, b;
  5.                 b = 0;
  6.                 a = 5 / b;
  7.                 System.out.print("A");
  8.             }
  9.             catch(ArithmeticException e) {
  10.          System.out.print("B");         
  11.             }
  12.         }
  13.     }
a) A
b) B
c) Compilation Error
d) Runtime Error
Answer: b
8. What is the output of this program?
  1.     class exception_handling {
  2.         public static void main(String args[]) {
  3.             try {
  4.                 int a[] = {1, 2,3 , 4, 5};
  5.                 for (int i = 0; i < 7; ++i) 
  6.                     System.out.print(a[i]);
  7.             }
  8.             catch(ArrayIndexOutOfBoundsException e) {
  9.          System.out.print("0");         
  10.             }
  11.         }
  12.     }
a) 12345
b) 123450
c) 1234500
d) Compilation Error
Answer: b

Explanation: When array index goes out of bound then ArrayIndexOutOfBoundsException exceptio is thrown by the system.
9. What is the output of this program?
  1.     class exception_handling {
  2.         public static void main(String args[]) {
  3.             try {
  4.                 int i, sum;
  5.                 sum = 10;
  6.                 for (i = -1; i < 3 ;++i)
  7.                     sum = (sum / i);
  8.             }
  9.             catch(ArithmeticException e) {
  10.          System.out.print("0");         
  11.             } 
  12.             System.out.print(sum);
  13.         }
  14.     }
a) 0
b) 05
c) Compilation Error
d) Runtime Error
Answer: c

Explanation: Since sum is declared inside try block and we are trying to access it outside the try block it results in error.

10. What is the output of this program?
  1.     class exception_handling {
  2.         public static void main(String args[]) {
  3.             try {
  4.                 int a[] = {1, 2,3 , 4, 5};
  5.                 for (int i = 0; i < 5; ++i) 
  6.                     System.out.print(a[i]);
  7.                 int x = 1/0;
  8.             }
  9.             catch(ArrayIndexOutOfBoundsException e) {
  10.          System.out.print("A");         
  11.             }
  12.             catch(ArithmeticException e) {      
  13.                 System.out.print("B");
  14.             }
  15.         }
  16.     }
a) 12345
b) 12345A
c) 12345B
d) Comiplation Error
Answer: c

Explanation: There can be more than one catch for a single try block. Here Arithmetic exception(/ by 0) occurs instead of Array index out of bound exception, so 2nd catch block is executed.

Related

Multiple choice Questions and Answers Context-Aware Services of Cloud Computing for Freshers

1. When a mobile user is connected to the mobile service, how many sets of information is exchanged ? a) 1b) 2c) 3d) 4 Answer: b Explanation: Two different sets of information is exchanged betwee...

Computer Fundamentals Multiple choice Questions and Answers on Documentation for Freshers

1. STD stands for ____________ a) Software Test Documentsb) System Test Documentsc) Software Traced Documentsd) System Traced Documents Answer: a Explanation: STD which stands for Software test d...

Multiple choice Questions and Answers on Synchronization of Cloud Computing for Freshers

1. Which of the following is the most commonly used standard for performing synchronization? a) SyncMLb) SMILc) SMLd) None of the mentioned Answer: a Explanation: SyncML stands for Synchronizatio...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item