Visual Programming MCQs with Answers
Practice important Visual Programming MCQs with answers and explanations.
Chapter: 8
Q221:
Which method is used to get a string representation of an exception?
A. ToString()
B. Message()
C. Print()
D. ExceptionString()
Correct Answer:
A
Chapter: 8
Q222:
What exception type would File.OpenRead likely throw if the file is not found?
A. FileNotFoundException
B. SecurityException
C. IOException
D. DirectoryNotFoundException
Correct Answer:
A
Chapter: 8
Q223:
In C#, how do you handle multiple exceptions separately?
A. Using multiple try blocks
B. Using multiple finally blocks
C. Using multiple catch blocks
D. Using catch inside finally
Correct Answer:
C
Chapter: 8
Q224:
What is the correct order of execution in a try-catch block?
A. try -> finally -> catch
B. try -> catch -> finally
C. catch -> try -> finally
D. finally -> try -> catch
Correct Answer:
B
Chapter: 8
Q225:
Which of the following is NOT a correct way to catch an exception in C#?
A. catch(Exception ex)
B. catch(FileNotFoundException fnfex)
C. catch(int ex)
D. catch(SystemException ex)
Correct Answer:
C
Chapter: 8
Q226:
How do you trigger a custom event in C#?
A. By calling the event like a method
B. By assigning a delegate
C. By declaring a new delegate
D. By creating a new class
Correct Answer:
A
Chapter: 8
Q227:
What is the correct way to register a method to an event in C#?
A. event += new EventHandler(methodName);
B. event = methodName;
C. event -= methodName;
D. event += methodName;
Correct Answer:
D
Chapter: 8
Q228:
Which method is invoked when the custom event startevent is fired?
A. onclickmeclicked
B. onstartevent
C. startdelegate
D. run
Correct Answer:
B
Chapter: 9
Q229:
What is the purpose of the finally block in exception handling?
A. To handle exceptions
B. To perform cleanup actions
C. To skip exceptions
D. To log errors
Correct Answer:
B
Chapter: 9
Q230:
Which file operation is performed in the finallydemo class?
A. Reading a file
B. Writing to a file
C. Closing a file
D. Opening a file
Correct Answer:
C
Chapter: 9
Q231:
What happens if an exception occurs during file operations in the try block?
A. The program terminates abruptly
B. The exception is ignored
C. The exception is caught and handled
D. The exception is re-thrown
Correct Answer:
C
Chapter: 9
Q232:
Which of the following best describes an attribute in C#?
A. A function
B. A method
C. A class
D. A declarative tag
Correct Answer:
D
Chapter: 9
Q233:
What attribute causes a compile-time warning if a method is used?
A. Obsolete
B. Serializable
C. STAThread
D. CLSCompliant
Correct Answer:
A
Chapter: 9
Q234:
What is the effect of the [Obsolete] attribute?
A. It marks a method as deprecated
B. It prevents a method from being used
C. It improves method performance
D. It changes method visibility
Correct Answer:
A
Chapter: 9
Q235:
Which of the following correctly declares an enumeration in C#?
A. public enum Volume { Low, Medium, High }
B. enum Volume { Low, Medium, High }
C. enum Volume { Low=1, Medium, High }
D. enum Volume : byte { Low, Medium, High }
Correct Answer:
A
Chapter: 9
Q236:
What is the default underlying type of an enum in C#?
A. byte
B. int
C. short
D. long
Correct Answer:
B
Chapter: 9
Q237:
How do you perform an explicit cast from int to an enum type in C#?
A. (int)enumType
B. (enumType)intValue
C. (enumType)parseInt(value)
D. (int)Enum.Parse(enumType)
Correct Answer:
B
Chapter: 9
Q238:
Which method is used to get all values from an enum type?
A. Enum.GetNames
B. Enum.Parse
C. Enum.GetValues
D. Enum.ToString
Correct Answer:
C
Chapter: 9
Q239:
Which of the following operators can be overloaded in C#?
A. +
B. +=
C. &&
D. .
Correct Answer:
A
Chapter: 9
Q240:
Which access modifier provides the highest level of encapsulation?
A. private
B. protected
C. internal
D. public
Correct Answer:
A