Program
using System;
namespace ConsoleApp4
{
class Program
{
static void Main(string[] args)
{
B x = new B();
x.show();
}
}
public class A //base class
{
protected int no = 1;
public void show()
{
Console.WriteLine(no);
}
}
public class B : A //sub class
{
protected int no = 100;
}
}
Output 1
How do I use sub Class attribute value instead of base class attribute value?
I tried override, new keywords and it doesn't seem to work.
What I have learned regarding this question is: sub class holds both parent class attribute, and its own attribute.
But sub class attribute get hide by base class attribute, if it is intentional you can use new keyword.
Thank you