Sail E0 Webinar

MCQs

Total Questions : 10
Question 1. What will be the output of given code snippet?
 class program {     public static void Main(string[] args)     {         try         {             throw new NullReferenceException("C");             Console.WriteLine("A");         }         catch (ArithmeticException e)          {             Console.WriteLine("B");         }         Console.ReadLine();     } }
  1.    A
  2.    B
  3.    Compile time error
  4.    Runtime error
 Discuss Question
Answer: Option D. -> Runtime error


try block is throwing NullPointerException but the catch block is used to counter Arithmetic Exception. Hence NullPointerException occurs since no catch is there which can handle it, runtime error occurs.


Question 2. Which of these keywords must be used to monitor exceptions?
  1.    try
  2.    finally
  3.    throw
  4.    catch
 Discuss Question
Answer: Option A. -> try




Question 3. What would be the output of following code snippet?
{     try      {         int a, b;         b = 0;         a = 5 / b;         Console.WriteLine("A");     }     catch(ArithmeticException e)      {         Console.WriteLine("B");     }     finally     {         Console.WriteLine("C");     }     Console.ReadLine(); }
  1.    A
  2.    B
  3.    B C
  4.    Run time error
 Discuss Question
Answer: Option C. -> B C


finally keyword is used to execute before catch and try block is executed.
Output : B C


Question 4. Which of these keywords is not a part of exception handling?
  1.    try
  2.    finally
  3.    thrown
  4.    catch
 Discuss Question
Answer: Option C. -> thrown


Exception handling is managed via 5 keywords “ try, catch, throws, throw and finally.


Question 5. What will be the output of the given code snippet?
class Program {     public static void Main(string[] args)     {         try         {             int a = 1;             int b = 10 / a;             try             {                 if (a == 1)                     a = a / a - a;                 if (a == 2)                 {                     int[] c = { 1 };                     c[8] = 9;                 }             }             finally             {                 Console.WriteLine("A");             }        }        catch (IndexOutOfRangeException e)        {             Console.WriteLine("B");        }        Console.ReadLine();    } }
  1.    A
  2.    B
  3.    AB
  4.    BA
 Discuss Question
Answer: Option A. -> A




Question 6. What would be the output of given code snippet?
class Program {     static void Main(string[] args)     {         int i;         int v = 40;         int[] x = new int[5];         try         {             Console.WriteLine(" Enter the number: ");             index = Convert.ToInt32(Console.ReadLine());             x[index] = v;         }         catch(Exception e)         {             Console.WriteLine("Exception occured");         }         Console.WriteLine("Program executed");     } }
  1.    Exception occured
  2.    Program executed
  3.    Exception occured Program executed
  4.    Program executed Exception occured
 Discuss Question
Answer: Option C. -> Exception occured Program executed




Question 7. Choose the correct statement among the following?
  1.    A property can be a static member whereas an indexer is always an instance member
  2.    A get accessor of a property corresponds to a method with no parameters whereas get accessor of an indexer corresponds to a method with the same formal parameters lists as the indexer
  3.    It is an error for indexer to declare a local variable with the same name as indexer parameters
  4.    All of the mentioned
 Discuss Question
Answer: Option D. -> All of the mentioned




Question 8. Consider a class maths and we had a property called as sum.b is a reference to a maths object and we want the statement b.sum = 10 to fail.Which of the following is the correct solution to ensure this functionality?
  1.    Declare sum property with both get and set accessors
  2.    Declare sum property with only get accessor
  3.    Declare sum property with get, set and normal accessors
  4.    None of the mentioned
 Discuss Question
Answer: Option C. -> Declare sum property with get, set and normal accessors




Question 9. Which of these keywords are used for the block to handle the exceptions generated by try block?
  1.    try
  2.    catch
  3.    throw
  4.    check
 Discuss Question
Answer: Option B. -> catch




Question 10. Consider a class maths and we had a property called as sum.b which is the reference to a maths object and we want the statement Console.WriteLine(b.sum)to fail.Which among the following is the correct solution to ensure this functionality?
  1.    Declares sum property with only get accessor
  2.    Declares sum property with only set accessor
  3.    Declares sum property with both set and get accessor
  4.    Declares sum property with both set, get and normal accessor
 Discuss Question
Answer: Option B. -> Declares sum property with only set accessor




Latest Videos

Latest Test Papers