Alright, so I’m currently learning inheritance, and I’ve done something, this is the code:
class array
{
int [] arr;
public array(int[] arr)
{
this.arr = arr;
}
public int Biggest()
{
return arr.Max();
}
public int Min()
{
return arr.Min();
}
public int SumArr()
{
return arr.Sum();
}
}
class array2 : array
{
public array2(int [] arr):base(arr)
{
}
public double Average()
{
return
}
}
Now, in the derived class I need to get the average of the array and I can’t do arr.Average()
The error says: Error 1 'ConsoleApplication1.array.arr' is inaccessible due to its protection level C:\Users\x\AppData\Local\Temporary Projects\ConsoleApplication1\Program.cs 35 20 ConsoleApplication1
Anyone can tell me what am I doing wrong?
Thanks for helpers!
arr is declared as private since you didn’t specify a visibility type. If you change it to protected, then your subclass array2 will be able to access it.