我有一个由多种方法调用的类。这个类是:
public class Policy : EntityObject
{
public Guid PolicyId { get; set; }
public Guid CustomerId { get; set; }
public string PolicyNumber { get; set; }
[NotMapped]
public string TrimmedPolicyNumber { get; set; }
public DateTime? PolicyEffectiveDate { get; set; }
public DateTime? PolicyExpirationDate { get; set; }
[NotMapped]
public string PolicyType { get; set; }
public string InsuranceCompany { get; set; }
public string WritingCompany { get; set; }
[NotMapped]
public string BillMethod_PaymentPlan { get; set; } …Run Code Online (Sandbox Code Playgroud) 在 Python 中,我有以下作为测验问题的代码:
class Big_Cat:
def __init__(self):
self.x = "dangerous"
class Cat(Big_Cat):
def __init__(self):
self.y = "quiet"
new_cat = Cat()
print(new_cat.x, new_cat.y)
Run Code Online (Sandbox Code Playgroud)
由于 cat 类继承自该类BigCat,因此它也应该有权访问变量x。那么为什么它会在打印屏幕行上抛出错误。还有什么方法可以从父级new_cat访问变量?x