Examveda

What will be the output of the following C# code?
class sample
{
    public  int i;
    void display() 
    {
        Console.WriteLine(i);
    }
}    
class sample1 : sample 
{
    public  int j;
    public void display() 
    {
        Console.WriteLine(j);
    }
}    
class Program
{
    static void Main(string[] args)
    {
        sample1 obj = new sample1();
        obj.i = 1;
        obj.j = 2;
        obj.display();
        Console.ReadLine();
    }
}

A. 1

B. 3

C. 2

D. Compile Time error

Answer: Option C


Join The Discussion

Related Questions on Classes and Objects in C Sharp