T
tired_of_spaghetti
I'm curious as to the need for the new keyword in an inherited method
redefinition, so -
Suppose I have a class hierachy that looks like
public class Base
{
public virtual void myMethod()
{...
}
}
public class Derived : Base
{
public void myMethod()
{...
}
}
if I tried
Base myObject = new Derived;
myObject.myMethod();
Would this produce a compile time (or runtime) error ? Or maybe this
just means that myObject cannot be used polymorphically as in -
Base myObject1 = new Base;
Base myObject2 = new Derived;
myObject1 = myObject2;
Now if instead of override I use new, all this apparently does is get
rid of the compiler warning. I'm confused.
Thanks in advance,
redefinition, so -
Suppose I have a class hierachy that looks like
public class Base
{
public virtual void myMethod()
{...
}
}
public class Derived : Base
{
public void myMethod()
{...
}
}
produces a warning and the Base class version is hidden, meaning thatFrom what I understand, without the override keyword the compiler
if I tried
Base myObject = new Derived;
myObject.myMethod();
Would this produce a compile time (or runtime) error ? Or maybe this
just means that myObject cannot be used polymorphically as in -
Base myObject1 = new Base;
Base myObject2 = new Derived;
myObject1 = myObject2;
Now if instead of override I use new, all this apparently does is get
rid of the compiler warning. I'm confused.
Thanks in advance,