A Student class has a public property called Sid and std is reference to Student object . Now we want the statement Console.WriteLine(std.Sid) to be failed during compilation. Which of the following options will ensure this functionality?
Declare Sid property with both get and set accessors.
Declare sid property with only set accessor.
Declare sid property with only get accessor.
None of the above
If you declare a property with only set accessor, then the user is allowed to set data only. Hence Console.WriteLine(std.Sid) will be failed during compilation,because the code is writing to access get accessor of the property which is not existing .
Back To Top