Sunday, June 1, 2014

Base class referring to an instance of a derived class

what are you trying to achieve, because you cant declear Person p = new Student();


do u want to access variables that are in the Base class.


And to answer your Question you cant. if im getting your question correctly.


but for instance you can do this:




internal class A
{
public static void Aa()
{
Console.WriteLine("Base Class!");
}
}
internal class B:A
{
public static void Bb()
{
Console.WriteLine("Dervide Class!");
}
}
class Program
{
static void Main(string[] args)
{
B.Aa();//correct
B base = new A();//incorrect
Console.ReadLine();
}
}






No comments:

Post a Comment