R
relient
Hi, I just started the chapter on "Inheritance" and I'm a bit confused
so I have three questions: first, here's the code:
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleProject1
{
public class Base
{
public virtual void SomeMethod( )
{
Console.WriteLine("Inside: Base.SomeMethod.");
}
}
public class Derived : Base
{
public override void SomeMethod( )
{
base.SomeMethod( );
}
}
public class MainClass
{
public static void Main( )
{
Derived d = new Derived( );
d.SomeMethod( );
}
}
}
1.)
In the above example, shouldn't Derived.SomeMethod() call itself
(infinite loop) because
I overrided the base method implimentation? meaning, Base.SomeMethod
does not "exist" anymore but only my implimentation of SomeMethod() in
the Derived class?
2.)
If I instead marked the method in the derived class with the "new"
keyword, I would have
access to two implimentations of the same method name:
Base.SomeMethod() and Derived.SomeMethod(),.. no?
3.)
When you inherit from a base class, the effect is exactly the same as
if you had explicitly declared the inherited members in your derived
class, true or false?
Thanks in advance,
relient.
so I have three questions: first, here's the code:
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleProject1
{
public class Base
{
public virtual void SomeMethod( )
{
Console.WriteLine("Inside: Base.SomeMethod.");
}
}
public class Derived : Base
{
public override void SomeMethod( )
{
base.SomeMethod( );
}
}
public class MainClass
{
public static void Main( )
{
Derived d = new Derived( );
d.SomeMethod( );
}
}
}
1.)
In the above example, shouldn't Derived.SomeMethod() call itself
(infinite loop) because
I overrided the base method implimentation? meaning, Base.SomeMethod
does not "exist" anymore but only my implimentation of SomeMethod() in
the Derived class?
2.)
If I instead marked the method in the derived class with the "new"
keyword, I would have
access to two implimentations of the same method name:
Base.SomeMethod() and Derived.SomeMethod(),.. no?
3.)
When you inherit from a base class, the effect is exactly the same as
if you had explicitly declared the inherited members in your derived
class, true or false?
Thanks in advance,
relient.