MCQOPTIONS
Saved Bookmarks
This section includes 63 Mcqs, each offering curated multiple-choice questions to sharpen your C Sharp Programming knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
Which of the following is/are an exception? |
| A. | Only ii) |
| B. | Only iii) |
| C. | i), ii), iii) and iv) |
| D. | Only iv)View Answer |
| Answer» D. Only iv)View Answer | |
| 2. |
How many predefined exceptions does SPL provide access to? |
| A. | 13 |
| B. | 14 |
| C. | 15 |
| D. | 16 |
| Answer» B. 14 | |
| 3. |
What does SPL stand for? |
| A. | Standard PHP Library |
| B. | Source PHP Library |
| C. | Standard PHP List |
| D. | Source PHP List |
| Answer» B. Source PHP Library | |
| 4. |
You can extend the exception base class, but you cannot override any of the preceding methods because the are declared as__________ |
| A. | protected |
| B. | final |
| C. | static |
| D. | private |
| Answer» C. static | |
| 5. |
Which one of the following is the right description for the method getMessage()? |
| A. | Returns the message if it is passed to the constructor |
| B. | Returns the message if it is passed to the class |
| C. | Returns the message if it is passed to the file |
| D. | Returns the message if it is passed to the object |
| Answer» B. Returns the message if it is passed to the class | |
| 6. |
Which of the following statements invoke the exception class? |
| A. | throws new Exception(); |
| B. | throw new Exception(); |
| C. | new Exception(); |
| D. | new throws Exception(); |
| Answer» C. new Exception(); | |
| 7. |
Which version added the method getPrevious()? |
| A. | PHP 4 |
| B. | PHP 5 |
| C. | PHP 5.1 |
| D. | PHP 5.3 |
| Answer» E. | |
| 8. |
How many methods are available for the exception class? |
| A. | 5 |
| B. | 6 |
| C. | 7 |
| D. | 8 |
| Answer» D. 8 | |
| 9. |
Which version of PHP was added with Exception handling? |
| A. | PHP 4 |
| B. | PHP 5 |
| C. | PHP 5.3 |
| D. | PHP 6 |
| Answer» C. PHP 5.3 | |
| 10. |
Why do we use finally block? |
| A. | To execute the block if exception occurred |
| B. | To execute a code when exception is not occurred |
| C. | To execute a code whenever required |
| D. | To execute a code with each and every run of program |
| Answer» E. | |
| 11. |
Which class is used to handle the input and output exceptions? |
| A. | InputOutput |
| B. | InputOutputExceptions |
| C. | IOExceptions |
| D. | ExceptionsIO |
| Answer» D. ExceptionsIO | |
| 12. |
Which symbol should be used to separate the type of exception handler classes in a single catch block? |
| A. | ? |
| B. | , |
| C. | – |
| D. | | |
| Answer» E. | |
| 13. |
Multiple catch blocks __________________ |
| A. | Are mandatory for each try block |
| B. | Can be combined into a single catch block |
| C. | Are not possible for a try block |
| D. | Can never be associated with a single try block |
| Answer» C. Are not possible for a try block | |
| 14. |
To catch the exceptions ___________________ |
| A. | An object must be created to catch the exception |
| B. | A variable should be created to catch the exception |
| C. | An array should be created to catch all the exceptions |
| D. | A string have to be created to store the exception |
| Answer» B. A variable should be created to catch the exception | |
| 15. |
Which among the following is not a method of Throwable class? |
| A. | public String getMessage() |
| B. | public Throwable getCause() |
| C. | public Char toString() |
| D. | public void printStackTrace() |
| Answer» D. public void printStackTrace() | |
| 16. |
How many catch blocks can a single try block can have? |
| A. | Only 1 |
| B. | Only 2 |
| C. | Maximum 127 |
| D. | As many as required |
| Answer» E. | |
| 17. |
There can be a try block without catch block but vice versa is not possible. |
| A. | True |
| B. | False |
| Answer» B. False | |
| 18. |
Which are the two blocks that are used to check error and handle the error? |
| A. | Try and catch |
| B. | Trying and catching |
| C. | Do and while |
| D. | TryDo and Check |
| Answer» B. Trying and catching | |
| 19. |
What are two exception classes in hierarchy of java exceptions class? |
| A. | Runtime exceptions only |
| B. | Compile time exceptions only |
| C. | Runtime exceptions and other exceptions |
| D. | Other exceptions |
| Answer» D. Other exceptions | |
| 20. |
Which is the universal exception handler class? |
| A. | Object |
| B. | Math |
| C. | Errors |
| D. | Exceptions |
| Answer» E. | |
| 21. |
If a file that needs to be opened is not found in the target location then _____________ |
| A. | Exception will be produced |
| B. | Exceptions are not produced |
| C. | Exception might get produced because of syntax |
| D. | Exceptions are not produced because of logic |
| Answer» B. Exceptions are not produced | |
| 22. |
An exception may arise when _______________ |
| A. | Input is fixed |
| B. | Input is some constant value of program |
| C. | Input given is invalid |
| D. | Input is valid |
| Answer» D. Input is valid | |
| 23. |
Why do we need to handle exceptions? |
| A. | To prevent abnormal termination of program |
| B. | To encourage exception prone program |
| C. | To avoid syntax errors |
| D. | To save memory |
| Answer» B. To encourage exception prone program | |
| 24. |
What is an exception? |
| A. | Problem arising during compile time |
| B. | Problem arising during runtime |
| C. | Problem in syntax |
| D. | Problem in IDE |
| Answer» C. Problem in syntax | |
| 25. |
What happens when ‘1’ == 1 is executed? |
| A. | we get a True |
| B. | we get a False |
| C. | an TypeError occurs |
| D. | a ValueError occurs |
| Answer» C. an TypeError occurs | |
| 26. |
Can one block of except statements handle multiple exception? |
| A. | yes, like except TypeError, SyntaxError [,…] |
| B. | yes, like except [TypeError, SyntaxError] |
| C. | no |
| D. | none of the mentioned |
| Answer» B. yes, like except [TypeError, SyntaxError] | |
| 27. |
Is the following Python code valid? |
| A. | no, there is no such thing as finally |
| B. | no, finally cannot be used with except |
| C. | no, finally must come before except |
| D. | yesView Answer |
| Answer» C. no, finally must come before except | |
| 28. |
How many except statements can a try-except block have? |
| A. | zero |
| B. | one |
| C. | more than one |
| D. | more than zero |
| Answer» E. | |
| 29. |
What is the output of this program?Note : Execution command line : $ java exception_handling |
| A. | 0 |
| B. | 1 |
| C. | Compilation Error |
| D. | Runtime Error |
| Answer» C. Compilation Error | |
| 30. |
Output of following Java program? |
| A. | Compiler Error |
| B. | Compiles and runs fine |
| C. | Compiles fine but throws ArithmeticException exception |
| D. | None of the above |
| Answer» D. None of the above | |
| 31. |
What is the output of this program?Note : Execution command line : $ java exception_handling one |
| A. | TypeA |
| B. | TypeB |
| C. | Compilation Error |
| D. | Runtime Error |
| Answer» D. Runtime Error | |
| 32. |
At Point X on line 5, which code is necessary to make the code compile? |
| A. | No code is necessary. |
| B. | throws Exception |
| C. | catch ( Exception e ) |
| D. | throws RuntimeException |
| Answer» C. catch ( Exception e ) | |
| 33. |
Predict the output of following Java program? |
| A. | Got the Exception 10 |
| B. | Got the Exception 0 |
| C. | Compiler Error |
| D. | None of the above |
| Answer» D. None of the above | |
| 34. |
Given that EOFException and FileNotFoundException are both subclasses of IOException, and further assuming this block of code is placed into a class, which statement is most true concerning this code? |
| A. | The code will not compile. |
| B. | Code output: Start Hello world File Not Found. |
| C. | Code output: Start Hello world End of file exception. |
| D. | Code output: Start Hello world Catch Here File not found. |
| Answer» B. Code output: Start Hello world File Not Found. | |
| 35. |
Given that all methods of class FileOutputStream, including close(), throw an IOException, which of these is true? |
| A. | This program will compile successfully. |
| B. | This program fails to compile due to an error at line 4. |
| C. | This program fails to compile due to an error at line 6. |
| D. | This program fails to compile due to an error at line 18. |
| Answer» E. | |
| 36. |
Which answer most closely indicates the behavior of the program? |
| A. | The program will not compile. |
| B. | The program will print Hello world, then will print that a RuntimeException has occurred, then will print Done with try block, and then will print Finally executing. |
| C. | The program will print Hello world, then will print that a RuntimeException has occurred, and then will print Finally executing. |
| D. | The program will print Hello world, then will print Finally executing, then will print that a RuntimeException has occurred. |
| Answer» E. | |
| 37. |
What is the output of this program?Note: Execution command line: $ java exception_handling one two |
| A. | TypeA |
| B. | TypeB |
| C. | Compilation Error |
| D. | Runtime Error |
| Answer» D. Runtime Error | |
| 38. |
Which statement is true? |
| A. | catch(X x) can catch subclasses of X where X is a subclass of Exception. |
| B. | The Error class is a RuntimeException. |
| C. | Any statement that can throw an Error must be enclosed in a try block. |
| D. | Any statement that can throw an Exception must be enclosed in a try block. |
| Answer» B. The Error class is a RuntimeException. | |
| 39. |
Which four can be thrown using the throw statement?1. Error2. Event3. Object4. Throwable5. Exception6. RuntimeException |
| A. | 1, 2, 3 and 4 |
| B. | 2, 3, 4 and 5 |
| C. | 1, 4, 5 and 6 |
| D. | 2, 4, 5 and 6 |
| Answer» D. 2, 4, 5 and 6 | |
| 40. |
At runtime, error is recoverable. |
| A. | True |
| B. | False |
| C. | May be |
| D. | Can't say |
| Answer» C. May be | |
| 41. |
Which of these is a super class of all errors and exceptions in the Java language? |
| A. | Catchable |
| B. | Throwable |
| C. | RunTimeExceptions |
| D. | None of the above |
| Answer» C. RunTimeExceptions | |
| 42. |
Which of the following keywords is used for throwing exception manually? |
| A. | finally |
| B. | try |
| C. | throw |
| D. | catch |
| Answer» D. catch | |
| 43. |
Choose the correct statement which makes exception handling work in C#.NET? |
| A. | .Net runtime makes search for the exception handler where exception occurs |
| B. | If no exception is matched, exception handler goes up the stack and hence finds the match there |
| C. | If no match is found at the highest level of stack call, then unhandledException is generated and hence termination of program occurs |
| D. | All of the mentioned |
| Answer» E. | |
| 44. |
Which of the following is the wrong statement about exception handling in C#.NET? |
| A. | finally clause is used to perform cleanup operations of closing network and database connections |
| B. | a program can contain multiple finally clauses |
| C. | the statement in final clause will get executed no matter whether an exception occurs or not |
| D. | all of the mentioned |
| Answer» C. the statement in final clause will get executed no matter whether an exception occurs or not | |
| 45. |
If math class had add property with get and set accessors, then which of the following statements will work correctly? |
| A. | math.add = 20; |
| B. | math m = new math(); m.add = 10; |
| C. | Console.WriteLine(math.ad |
| D. | ;d) None of the mentioned |
| Answer» C. Console.WriteLine(math.ad | |
| 46. |
It is compulsory for all classes whose objects can be thrown with throw statement to be derived from System.Exception class. |
| A. | 1 |
| B. | |
| Answer» C. | |
| 47. |
Which of the following statements is correct about the C#.NET program given below if a value "ABCD" is input to it? using System; namespace IndiabixConsoleApplication { class MyProgram { static void Main(string[] args) { int index; int val = 55; int[] a = new int[5]; try { Console.Write("Enter a number: "); index = Convert.ToInt32(Console.ReadLine()); a[index] = val; } catch(FormatException e) { Console.Write("Bad Format "); } catch(IndexOutOfRangeException e) { Console.Write("Index out of bounds "); } Console.Write("Remaining program "); } } } |
| A. | It will output: Bad Format |
| B. | It will output: Remaining program |
| C. | It will output: Index out of bounds |
| D. | It will output: Bad Format Remaining program |
| Answer» E. | |
| 48. |
Exceptions can be thrown even from a constructor, whereas error codes cannot be returned from a constructor. |
| A. | 1 |
| B. | |
| Answer» B. | |
| 49. |
Which of the following statements are correct about the exception reported below? Unhandled Exception: System.lndexOutOfRangeException: Index was outside the bounds of the array: at IndiabixConsoleApplication.MyProgram.SetVal(Int32 index, Int32 val) in D:\Sample\IndiabixConsoleApplication\MyProgram.cs:line 26 at IndiabixConsoleApplication.MyProgram.Main(String[] args) in D:\Sample\IndiabixConsoleApplication\MyProgram.cs:line 20 The CLR failed to handle the exception. The class MyProgram belongs to the namespace MyProgram. The function SetVal() was called from Main() in line number 20. The exception occurred in line number 26 in the function SetVal() The runtime exception occurred in the project IndiabixConsoleApplication. |
| A. | 1 only |
| B. | 1 and 2 only |
| C. | 3, 4 and 5 only |
| D. | All of the above |
| Answer» D. All of the above | |
| 50. |
Which of the following is the Object Oriented way of handling run-time errors? |
| A. | OnError |
| B. | HERESULT |
| C. | Exceptions |
| D. | Error codes |
| Answer» D. Error codes | |