What will be the output of the following C# code? [code] namespace ConsoleApplication4 { class A { public int i;

Thảo Justin

New member
What will be the output of the following C# code?
Code:
 namespace ConsoleApplication4
 {
     class A
     {
         public int i;
         public void display()
         {
             Console.WriteLine(i);
         }
     }    
     class B: A 
     {
         public int j;
         public void display() 
         {
             Console.WriteLine(j);
         }
     }    
     class Program
     {
         static void Main(string[] args)
         {
             B obj = new B();
             obj.j = 1;
             obj.i = 8;
             obj.display();
             Console.ReadLine();
         }
     }
 }
A. 8,
Code:
 1
B. 8
C.
Code:
 1
D.
Code:
 1
, 8
 
Answer: c
Explanation: Class A & class B both contain display() method, class B inherits class A, when display() method is called by object of class B, display() method of class B is executed rather than that of Class A.
Output:
Code:
 1
 

Tìm kiếm

Back
Top