我只是覺得現在真的很笨,你能幫我解釋爲什麼我用這個簡單的代碼有保護級別問題嗎?我甚至試圖把它通過對象,但仍然保護水平問題。這個簡單的程序爲什麼會給我提供保護級別的問題?
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();
}
}
這就是爲什麼你不使用隱含的知名度。 – Mephy 2014-09-29 05:13:48
「保護等級問題」是什麼意思? – 2014-09-29 05:13:52
就像它基本上突出顯示功能中的「第一,第二,添加」,並且說a.second,a,first和a.add由於其保護級別而不可訪問,但是該函數是公開的,並且我沒有聲明整數作爲私人 – 2014-09-29 05:16:30