T
Tony Johansson
Hello!
I have three classes below. These are Animal as a base class and one derived
class called Cat.
The main in within class Tester.
If I compile the program as it is now I get the following
Warning 1 'Cat.MyTest()' hides inherited member 'Animal.MyTest()'. To make
the current member override that implementation, add the override keyword.
Otherwise add the new keyword.
F:\C#\ConsoleApplication1\ConsoleApplication1\Animal.cs 17 21
ConsoleApplication1
I understand the warning message.
I know it's wrong to have it as I have without new and without override.
But what is it that I can't do when I have it as I have now. I just want to
know.
Because I'm not using override here there must be something that I can't do
because of that.
If I have it as I have how does the compiler interprete it when not using
new and not using override.
Will the method MyTest be considered as a new method with the same name as
the base class.
//Tony
using System;
class Animal
{
private void Test()
{
Console.WriteLine("Test");
}
public virtual void MyTest()
{
Test();
}
}
class Cat : Animal
{
public void MyTest()
{
base.MyTest();
}
}
class Tester
{
static void Main(string[] args)
{
Cat myCat = new Cat();
myCat.MyTest();
}
}
I have three classes below. These are Animal as a base class and one derived
class called Cat.
The main in within class Tester.
If I compile the program as it is now I get the following
Warning 1 'Cat.MyTest()' hides inherited member 'Animal.MyTest()'. To make
the current member override that implementation, add the override keyword.
Otherwise add the new keyword.
F:\C#\ConsoleApplication1\ConsoleApplication1\Animal.cs 17 21
ConsoleApplication1
I understand the warning message.
I know it's wrong to have it as I have without new and without override.
But what is it that I can't do when I have it as I have now. I just want to
know.
Because I'm not using override here there must be something that I can't do
because of that.
If I have it as I have how does the compiler interprete it when not using
new and not using override.
Will the method MyTest be considered as a new method with the same name as
the base class.
//Tony
using System;
class Animal
{
private void Test()
{
Console.WriteLine("Test");
}
public virtual void MyTest()
{
Test();
}
}
class Cat : Animal
{
public void MyTest()
{
base.MyTest();
}
}
class Tester
{
static void Main(string[] args)
{
Cat myCat = new Cat();
myCat.MyTest();
}
}