I am trying to execute the following code
class A
{
protected int a;
protected char b;
public void Show()
{
a=5;
MessageBox.Show(""+a);
}
}
class B:A
{
public void Show()
{
b='z';
MessageBox.Show(""+a+ ""+b);
}
}
I am getting 5 (value of a) as the output when I do aa.show() where aa is the instance of A but when I do bb.show(), where bb is the instance of B, the output comes out as 0 (value of a) z (value of b).
Can someone please explain why the derived class is unable to display the current value of a even though it has been declared as protected whereas it is able to display the correct value of b?
Update:
I'll try the solutions suggested. Regarding the compilation error, there was none and I was able to get the output as mentioned in the question.