What will be the Correct statement in the following C# code?
class sample
{
protected int index;
public sample()
{
index = 0;
}
}
class sample 1: sample
{
public void add()
{
index += 1;
}
}
class Program
{
static void Main(string[] args)
{
sample 1 z = new sample 1();
z . add();
}
}
class sample
{
protected int index;
public sample()
{
index = 0;
}
}
class sample 1: sample
{
public void add()
{
index += 1;
}
}
class Program
{
static void Main(string[] args)
{
sample 1 z = new sample 1();
z . add();
}
}A. Index should be declared as protected if it is to become available in inheritance chain
B. Constructor of sample class does not get inherited in sample 1 class
C. During constructing an object referred to by z, Firstly constructor of sample class will be called followed by constructor of sample 1 class
D. All of the mentioned
Answer: Option D
Related Questions on Classes and Objects in C Sharp
A. A blueprint for creating objects
B. A method in C#
C. A variable in C#
D. A data type in C#
A. A method in C#
B. A variable in C#
C. An instance of a class
D. A data type in C#
A. public
B. private
C. protected
D. internal

Join The Discussion