Hello
I have a question on the following console application
class A
{
public void F() { Console.WriteLine("A.F"); }
public virtual void G() { Console.WriteLine("A.G"); }
}
class B: A
{
new public void F() { Console.WriteLine("B.F"); }
public override void G() { Console.WriteLine("B.G"); }
}
class Test
{
static void Main() {
B b = new B();
A a = b;
a.F();
b.F();
a.G();
b.G();
}
}
One object is created here and that is of type B that inherits from A. The A-type variable a is assigned b's reference, so it as well points to the b object...right?
why a.F() results in "A.F" and a.G() in "B.G"?
I have a question on the following console application
class A
{
public void F() { Console.WriteLine("A.F"); }
public virtual void G() { Console.WriteLine("A.G"); }
}
class B: A
{
new public void F() { Console.WriteLine("B.F"); }
public override void G() { Console.WriteLine("B.G"); }
}
class Test
{
static void Main() {
B b = new B();
A a = b;
a.F();
b.F();
a.G();
b.G();
}
}
One object is created here and that is of type B that inherits from A. The A-type variable a is assigned b's reference, so it as well points to the b object...right?
why a.F() results in "A.F" and a.G() in "B.G"?