我有以下抽象类:
abstract class Customer
{
private string address { get; set; }
private int phone { get; set; }
public Customer(string address, int phone)
{
this.address = address;
this.phone = phone;
}
}
然后,我有以下从客户类继承的类:
class Private : Customer
{
private string name { get; set; }
private int age { get; set; }
private string sex { get; set; }
public Private(string name, int age, string sex, string address, int phone) : base(address, phone)
{
this.name = name;
this.age = age;
this.sex = sex;
}
我的问题是:如何访问我的私人班级的电话和地址字段?
使用protected
修饰符代替private
继承的类可以访问的所有内容。
从文档中:
受保护的成员可以在其类中以及通过派生类实例进行访问。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句