What will be the output of the following C# code? [code] class Output { public static void main(String args[]) {

Daniel William

New member
What will be the output of the following C# code?
Code:
 class Output 
 {
     public static void main(String args[]) 
     {
         try 
         {
             int a = 9;
             int b = 5;
             int c = a / b - 5;
             Console.WriteLine("Hello");
         }
         catch(Exception e) 
         {
             Console.WriteLine("C");
         } 
         finally 
         {
             Console.WriteLine("sharp");
         } 
     }
 }
A. Hello
B. C
C. Hellosharp
D. Csharp
 
Answer: d
Explanation: finally block execution takes place after the tryblock, no matter exception is found or not. catch block is executed only when exception is found. Here divide by zero exception is found hence both catch and finally are executed.
 

Tìm kiếm

Back
Top