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 23

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


Johan

Johan

i believe the answer to this is E.

suo

suo

it says two actions

Tamil

Tamil

u mean the answer is AF

Gehan

Gehan

Answer is D,E

Poland

Poland

There is NO proper answer choosing two actions. I’m 100% sure the D is right.

Poland

Poland

Sorry the E is right. D is totally wrong.

karfik

karfik

I also believe the correct answer is E. This question is badly specified. You can compile ONLY this case to meet question’s requirements:

public class Employee {
protected string EmpType
{
get;
set;
}
}

My'nD

My'nD

Answer is AF
Compiling as is would make the property accessible from everything in the assembly.
A private get is wrong too as the property must be accessed AND modified bye the code within the class and derived class, both properties have to be protected to be accessed by derived class too, but nothing else.

PaulC

PaulC

Wrong, you cant specify both modifiers same like this:

internal string EmpType
{
protected get;
protected set;
}

this won‘t compile.

Hich

Hich

internal string EmpType
{
protected string get;
protected string set;
}

will not compile, because ‘protected’ is more restrictive than ‘internal’

My'nD

My'nD

PS: and DF would be redundant, D would answer alone, without the need to put the set as protected.

宾宾

宾宾

如果是AF的话,VS会提示不能为两个访问器同时指定可访问修饰符。所以我猜这道题可能有问题,可选择答案应该是E。

vishal

vishal

could u be specific which 1 is the correct answer… i have encountered similar question which says E and F……PLZ RPLY

Tenkaito

Tenkaito

The correct answer is “E”. I think the question is wrong.
You can test the code by your own and will check that “E” is the correct answer.

PaulC

PaulC

The question is wrong. There is a part missing.
The correct question was:

The EmployeeType property value must be accessed only by code within the
Employee class or within a class derived from the Employee class and modified only within the Employe class.

Then, the correct answer is: BE

protected string EmpType { get; private set;}

this is a quite common way yo work with properties within base classes.

kasp

kasp

yes, this makes sense. Thanks

kasp

kasp

See question 73

zz

zz

thanks a lot for posting the correct question!

jeff

jeff

answer should be BE, tested.
first the function has to be protected, to be used only by class and its derived, then if you assign the “setter” to be protected, the system will mark it as a mistake and remind you that the setter has to be more restricted than the method, so it has to be private.

Abel

Abel

yes PaulC is right, thank you.. even this does not work when compiled as the question recommends

internal string EmpType
{
protected get;
private set;
}

So the Question is wrong, as it not possible to assciate between internal and protected both are more restrictive each other.

mahesh

mahesh

I Guess Ans is E