Tag: programming languages

Questions Related to programming languages

  1. ArithmeticException

  2. RunTimeException

  3. NumberFormatException

  4. NumberError


Correct Option: C
Explanation:

To solve the question, the user needs to know what parseInt() method does. The parseInt() method is used to convert a string to an integer. If the string argument cannot be parsed as an integer, parseInt() throws a NumberFormatException.

Now, let's go through each option and explain why it is right or wrong:

A. NumberError: There is no exception called NumberError in Java. This option is incorrect.

B. ArithmeticException: The ArithmeticException is thrown when an exceptional arithmetic condition has occurred. Since parseInt() throws a NumberFormatException, this option is incorrect.

C. RunTimeException: RuntimeException is a superclass of all classes that represent exceptional conditions that occur during the execution of Java code. Since NumberFormatException is a subclass of RuntimeException, this option is partially correct. However, the specific exception thrown by parseInt() is NumberFormatException.

D. NumberFormatException: This is the correct answer. When parseInt() gets illegal data, it throws a NumberFormatException. This exception is thrown to indicate that the application has attempted to convert a string to one of the numeric types, but that the string does not have the appropriate format.

Therefore, the answer is: D. NumberFormatException.

  1. Some of the statements in a try{} block will never throw an exception.

  2. The statements in a try{} block may throw several types of exception.

  3. The try{} block can not contain loops or branches.

  4. The try{} block must appear before the catch{} blocks.


Correct Option: C
Explanation:

To answer this question, the user needs to know about the try-catch-finally block in exception handling.

Option A is true because not all statements in a try{} block will throw an exception, some statements may never throw an exception.

Option B is true because the statements in a try{} block may throw several types of exception.

Option C is false because the try{} block can contain loops and branches.

Option D is false because the try{} block can appear anywhere in the try-catch-finally block, as long as it appears before the catch{} and finally{} blocks.

Therefore, the answer is:

The Answer is: C. The try{} block can not contain loops or branches.

  1. There can be several catch{} blocks in a try/catch structure.

  2. The catch{} block for a child exception class must PRECEED that of a parent execption class.

  3. The catch{} block for a child exception class must FOLLOW that of a parent execption class.

  4. If there is no catch{} block there must be a finally{} block.


Correct Option: C
  1. This is not legal, so the program will not compile.

  2. The method throws the exception to its caller if there were no matching catch{} block.

  3. The program halts immediately.

  4. The program ignores the exception.


Correct Option: B
  1. There must always be one, following the last catch{} block.

  2. There can be zero or one immediately after each catch{} block.

  3. There can be zero or one, following the last catch{} block.

  4. There can be any number, following the last catch{} block.


Correct Option: C
  1. Only when an unhandled exception is thrown in a try{} block.

  2. Only when any exception is thrown in a try{} block.

  3. Always after execution has left a try{} block, no matter for what reason.

  4. Always just as a method is about to finish.


Correct Option: C
  1. A type of coffee

  2. An object-oriented programming language

  3. An interactive website

  4. None of the above


Correct Option: B
  1. Type of computer

  2. A Java program that is run through a web browser

  3. An interactive website

  4. A type of fruit


Correct Option: B
  1. Windows

  2. Unix/Linux

  3. Mac

  4. All of the Above


Correct Option: D