I've got the code below and I'm trying to do some inheritance exercises but when I try to run this code it gives me an error:
Inconsistent Accessability: Base Class is less accessible than class
The code:
class Program
{
static void Main()
{
FoodProducts Test = new FoodProducts();
Test.Limit();
}
}
public class FoodProducts : Products
{
public void FoodProduct()
{
Console.WriteLine("This is food product");
}
public void Limit()
{
Console.WriteLine("This is an Attribute of a Product");
}
}
Would someone be able to help me?
Just for future reference for someone thick like me, I got this in the following situation and couldn't figure out what was going wrong:
public class Foo : Base<Bar> {} <-- Inconsistent accessibility
public class Base<T> {}
It took me a while to work out that the culprit was here:
internal class Bar {}
What line is the error on, and what is the specific error text? Also, where is the definition of Products
?
You are probably getting CS0060: "Inconsistent accessibility: base class 'class1' is less accessible than class 'class2'" Thus, I'm assuming your Products
class is not marked as public
.
This problem happens when a base class is marked as something other than public
(internal
, for example), but then you try to make a public
derived class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With