Which two actions should you perform?

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.)

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;



Leave a Reply 10

Your email address will not be published. Required fields are marked *


TheCoder

TheCoder

“…accessed AND modified only by code within the employee class..”

I would say E does the trick on its own, why B? B will not allow derived classes to set the data…

If I’m required to pick two I will go with A & F or either E & A or E & F

Zach

Zach

yeah this is wrong. B is not correct…

sv1slim

sv1slim

The question is a bit wrong, if you change lines to any other code then in B and E you get error messages:

A: protected get; – error message “accessor must be more restrictive”
B: private set; – works fine as access modifier “private” is more restrictive.
C: public string EmployeeType; – will not make any restriction at all.
D: private get; – works fine as access modifier “private” is more restrictive.
E: protected EmployeeType; – right thing to do as you have to restrict property first.
F: protected set; – will not work too.

So if you want to answer the question, then it’s E: only.

Najlepszy Programista Swiata DAGO

Najlepszy Programista Swiata DAGO

E & A or E & F

B is incorrect

Ashraf

Ashraf

It must be A and F, where we set and get are protected (Accessed and modified by the enclosing class and by derived classes) while keeping the property internal.

Especially that the question requires choosing 2 options for a complete solution, otherwise we would’ve changing the property from internal to protected, but in this case the property could be accessed by derives classes out the assembly.

Accessing means get …. Modifying means set.

Ashraf

Ashraf

Correction to my early answer:

First: Protected on the same level of Internal, and as a rule of thumb, get and set accessors must be more restricted than the property access specifier.

So, either we set the property to public and setting get and set to protected, but in this case we need to choose 3 options not 2.

Or we choose only one option which is E, applying protected on the property itself and its accessors will follow their enclosing property level of restriction.

I second sv1slim answer.

Joe

Joe

The Question is wrong. The correct Question is Nr. 77.

Joe

Joe

In the Microsoft Test this question only needs one answer: E

#77 is different and needs two answers.