1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Drawing; 6 using System.Windows.Forms; 7 8 namespace BaseDemo 9 { 10 class BClass 11 { 12 public BClass() 13 { 14 Console.WriteLine("Welcome to China"); 15 } 16 17 public BClass(string a , string b) 18 { 19 Console.WriteLine( "Name:{0]",a); 20 Console.WriteLine( "Location:{0}",b); 21 } 22 } 23 24 //派生类 25 public class DClass:BClass 26 { 27 //这个构造函数会调用默认构造函数 28 public DClass() 29 : base() 30 { 31 } 32 33 //这个构造函数会调用有参构造函数 34 public DClass(string x, string y) 35 : base(x, y) 36 { 37 } 38 } 39 40 class Program 41 { 42 static void Main(string[] args) 43 { 44 DClass d = new DClass(); 45 DClass d1 = new DClass("Suresh Dasari","Hyderabad"); 46 Console.WriteLine("\nPress Enter Key to Exit..."); 47 Console.ReadLine(); 48 } 49 } 50 }
出现可访问性低的错误问题,是因为上面代码中第10行“class BClass”默认是private,而派生类public class DClass:BClass使用的是public修饰符,造成了派生类的可访问范围比基类的范围还大,所以出现了报错!
标签:Console,比类,DClass,System,访问,BClass,using,BaseDemo,public From: https://www.cnblogs.com/chenlight/p/16838589.html