This is my oops query.
This is my base class
public class BaseClass
{
public int i = 10;
public int x = 30;
public string str = "Hello";
public virtual string Hello()
{
return "Hello of base class called";
}
}
This is my child class
public class ChildClass : BaseClass
{
public int i = 20;
public int z = 90;
public override string Hello()
{
return "Hello of child class called";
}
}
I've since discovered that the code below is correct.
BaseClass baseObject = new ChildClass();
And only BaseClass members are displayed when I type baseObject.
Can someone provide me any advice regarding a scenario when a developer must execute BaseClass baseObject = new ChildClass()?
Why can't I access my child member variables through this baseObject if my BaseClass object contains a reference to my child class object?