主题:请问大家:书中这个例子是对的吗??
//书中有下面的抽象类定义及派生类.我不明白派生类中的属性能访问基类中的私有变量吗?
using System;
public abstract class Employee
{
private string name;
private long idcard;
public Employee(string n, long i)
{
name = n;
idcard = i;
}
public abstract string Name { get;set;}
public abstract long ID { get;set;}
}
public class WorkeEmp : Employee
{
public WorkeEmp(string n, long i) : base(n, i) { }
public override string Name
{
get { return name; } //能够访问基类的私有变量吗
set { name = value; }
}
public override long ID
{
get { return idcard; }
set { idcard = value; }
}
}
using System;
public abstract class Employee
{
private string name;
private long idcard;
public Employee(string n, long i)
{
name = n;
idcard = i;
}
public abstract string Name { get;set;}
public abstract long ID { get;set;}
}
public class WorkeEmp : Employee
{
public WorkeEmp(string n, long i) : base(n, i) { }
public override string Name
{
get { return name; } //能够访问基类的私有变量吗
set { name = value; }
}
public override long ID
{
get { return idcard; }
set { idcard = value; }
}
}