Not sure what you are looking for, but you can always call your base class
methods from an inherited class (assuming they are marked public or
protected). Adding base.HelloWorld() will make sure the "I am A" actually
gets registered. The inheritance chain has quite a few rules based around
constructors and method inheritance so you'll want to go through the process
of writing a few different examples and run through the C# language
documentation to make sure you understand all of the nuances.
using System;
public class A : System.Object {
public A() {
HelloWorld();
}
virtual public void HelloWorld() {
Console.WriteLine("I am A");
}
}
public class B : A {
public B() {
}
public override void HelloWorld() {
base.HelloWorld();
Console.WriteLine("I am B");
}
private static void Main() {
B MyB = new B();
}
}
--
Justin Rogers
DigiTec Web Consultants, LLC.
"Jim Owen" <jo***@saltmine.com> wrote in message
news:04****************************@phx.gbl...
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();
}
}