为什么这个简单的程序会给我保护级别问题?

0 c# polymorphism inheritance accessor

我现在觉得自己真的很蠢可以请你帮忙解决为什么我这个简单的代码有保护等级的问题?我甚至尝试通过对象调用它,但仍然保护级别问题.

class A
{
    int first, second, add;

    public void input()
    {
        Console.WriteLine("Please enter the first number: ");
        first = Convert.ToInt32(Console.ReadLine());
        Console.WriteLine("Please enter the second number: ");
        second = Convert.ToInt32(Console.ReadLine());
    }

    public void sum()
    {
        add = first + second;
    }
}

class B : A 
{       
    public void display()
    {
        Console.WriteLine("You entered {0} and {1} the sum of two numbers is {3}",first,second,add); //<<<<<<<< here

    }
}

class Program
{
    static void Main(string[] args)
    {
        A acall = new A();
        B bcall = new B();

        acall.input();
        acall.sum();
        bcall.display();
    }
}
Run Code Online (Sandbox Code Playgroud)

Wil*_*mpt 5

因为字段的默认可见性是"私有".

您没有明确指定"第一","第二"和"添加"的可见性,因此"第一","第二"和"添加"是A类的私有字段,在B类中不可见.