C# Programming - Properties - Discussion

Discussion :: Properties - General Questions (Q.No.3)


A Student class has a property called rollNo and stu is a reference to a Student object and we want the statement stu.RollNo = 28 to fail. Which of the following options will ensure this functionality?

[A]. Declare rollNo property with both get and set accessors.
[B]. Declare rollNo property with only set accessor.
[C]. Declare rollNo property with get, set and normal accessors.
[D]. Declare rollNo property with only get accessor.
[E]. None of the above

Answer: Option D


No answer description available for this question.

Ram said: (Aug 24, 2013)  
In property, get accessor implies read only and set accessor implies write only. So here we want to stop setting a value. Remove set accessor.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.