【问题标题】:Inconsistent accessibility: Base class is less accessible than parent class [duplicate]可访问性不一致:基类比父类更难访问[重复]
【发布时间】:2018-12-15 14:59:57
【问题描述】:

可访问性不一致:基类的可访问性不如父类。 错误出现在基类 Circle 和 Oval 上。我认为大括号没有问题。我该如何解决?

namespace CheckingPolymor
    {
        class Shape
        {
            int width;
            int height;
            string color;

            public virtual void Draw()
            {

            }

        }

            public class Circle: Shape
            {
                public override void Draw()
                {
                    base.Draw();
                }
            }

            public class Oval: Shape
            {
                public override void Draw()
                {
                    base.Draw();
                }

            }                          
    }

【问题讨论】:

  • 你能分享一下确切的错误吗?
  • 公共或内部类 Shape

标签: c# html asp.net asp.net-mvc


【解决方案1】:

你也可以

  • 制作Shapepublic,或者
  • CircleOval 中删除public

出现此错误是因为您使访问修饰符毫无意义。在没有任何访问修饰符的情况下,Shapeinternal,它比它的子类 public 更难访问。通过访问子类,您还可以访问在超类中声明的成员。这使得 internal Shape 毫无意义。

【讨论】:

    猜你喜欢
    • 2012-10-27
    • 2013-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-07
    相关资源
    最近更新 更多