You are creating a class named Employee. The class exposes a string property named EmployeeType. The
following code segment defines the Employee class. (Line numbers are included for reference only.)
The EmployeeType property value must be accessed and modified only by code within the Employee class or
within a class derived from the Employee class.You need to ensure that the implementation of the EmployeeType property meets the requirements.
Which two actions should you perform? (Each correct answer represents part of the complete solution. Choose
two.)
A.
Replace line 05 with the following code segment:
protected get;
B.
Replace line 06 with the following code segment:
private set;
C.
Replace line 03 with the following code segment:
public string EmployeeType
D.
Replace line 05 with the following code segment:
private get;
E.
Replace line 03 with the following code segment:
protected string EmployeeType
F.
Replace line 06 with the following code segment:
protected set;
Explanation:
題庫上的答案是 ,但我個人覺得是 而己! A, F E
E and F
B and E
It’s just E alone.
Definitely not (B and E) – derived classes can’t modify it then. And it’s not (E and F) either, the accessibility of the accessor must be more restrictive than the accessibility of the property.
Exactly …question is not true
I agree. A and F (the answers marked green) will do the job as well since the result is the same, but doing it like stated in E is cleaner.