What will be the output of the following C# code? [code] class abc { public static void a() { console.writeline("first

What will be the output of the following C# code?
Code:
 class abc
 {
     public static void a()
     {
         console.writeline("first method");
     }
     public void b()
     {
         a();
         console.writeline("second method");
     }
     public void b(int i)
     {
         console.writeline(i);
         b();
     }
 }
 class program
 {
     static void main()
     {
         abc k = new abc();
         abc.a();
         k.b(20);
     }
 }
A.
second method
20
second method
first method
B.
first method
20
first method
second method
C.
first method
20
D.
second method
20
first method
 
Answer: b
Explanation: The class ‘abc’ first calls method()’a’ then object of class ‘k’ when calls method ‘b’. First of all, the method ‘a’ will be executed and then executes the second statement.
Output :
Code:
        first method
        20
        first method
        second method
 

Tìm kiếm

Back
Top