I have a simple C# code written after reading documentation about protected access modifier, but I am recieving a lot of illogical errors. I cant find any solutions to them.
using System;
public class WeaponController
{
protected void Reload()
{
Console.WriteLine("Reload");
}
protected virtual void Shoot()
{
}
}
public class SMGController : WeaponController
{
private override void Shoot()
{
Console.WriteLine("Shoot");
}
}
public class Test
{
public static void Main()
{
var test = new SMGController();
test.Shoot();
test.Reload();
}
}
And I am recieving following errors:
prog.cs(19,27): error CS0621:
SMGController.Shoot()': virtual or abstract members cannot be private prog.cs(19,27): error CS0507:
SMGController.Shoot()': cannot change access modifiers when overridingprotected' inherited member
WeaponController.Shoot()' prog.cs(10,25): (Location of the symbol related to previous error) Compilation failed: 2 error(s), 0 warnings
If I will change access modifier of Shoot() method in SMGController to protected I recieve even more errors:
prog.cs(30,8): error CS1540: Cannot access protected member
WeaponController.Shoot()' via a qualifier of type
SMGController'. The qualifier must be of typeTest' or derived from it prog.cs(10,25): (Location of the symbol related to previous error) prog.cs(30,8): error CS0122:
WeaponController.Shoot()' is inaccessible due to its protection level prog.cs(10,25): (Location of the symbol related to previous error) prog.cs(31,8): error CS1540: Cannot access protected memberWeaponController.Reload()' via a qualifier of type
SMGController'. The qualifier must be of typeTest' or derived from it prog.cs(5,17): (Location of the symbol related to previous error) prog.cs(31,8): error CS0122:
WeaponController.Reload()' is inaccessible due to its protection level prog.cs(5,17): (Location of the symbol related to previous error) Compilation failed: 4 error(s), 0 warnings
What is wrong with my code?