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)