J
Jim Owen
In the following code, as I understnad it, the resulting
display would be "I am B", because I have overridden the
constructor in B. However, what if what I really want to
do is display "I am A" followed by "I am B', so that A's
constructor is called, followed by B's constructor? Also,
does it work differently for constructors than it does for
other overridden methods?
public class A : System.Object
{
public A()
{
HelloWorld();
}
virtual public void HelloWorld()
{
Console.WriteLine("I am A");
}
}
public class B : A
{
public B()
{
}
override public void HelloWorld()
{
Console.WriteLine("I am B");
}
public void Main()
{
B MyB = new B();
}
}
display would be "I am B", because I have overridden the
constructor in B. However, what if what I really want to
do is display "I am A" followed by "I am B', so that A's
constructor is called, followed by B's constructor? Also,
does it work differently for constructors than it does for
other overridden methods?
public class A : System.Object
{
public A()
{
HelloWorld();
}
virtual public void HelloWorld()
{
Console.WriteLine("I am A");
}
}
public class B : A
{
public B()
{
}
override public void HelloWorld()
{
Console.WriteLine("I am B");
}
public void Main()
{
B MyB = new B();
}
}