Properties on C# related Questions and Answers

Question 2 : An Employee class has a property called age and emp is reference to a Employee object and we want the statement Console.WriteLine(emp.age) to fail. Which of the following options will ensure this functionality?
1. Declare age property with only get accessor.
2. Declare age property with only set accessor.
3. Declare age property with both get and set accessors.
4. Declare age property with get, set and normal accessors.
View Answer   Discuss with Members

Question 3 : An Account class has a property called accountNo and acc is a reference to a bank object and we want the C#.NET code snippet given below to work. Which of the following options will ensure this functionality?
acc.account No = 10;
Console.WriteLine(acc.accountNo);
1. Declare accountNo property with both get and set accessors.
2. Declare accountNo property with only get accessor.
3. Declare accountNo property with get, set and normal accessors.
4. Declare accountNo property with only set accessor.
View Answer   Discuss with Members

Question 4 : 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?
1. Declare rollNo property with both get and set accessors.
2. Declare rollNo property with only set accessor.
3. Declare rollNo property with get, set and normal accessors.
4. Declare rollNo property with only get accessor.
View Answer   Discuss with Members


View 1 - 5 of 5 Questions

* Be the First to Post a Comment.

Submit comment :


Captcha Image
Reload

Ask Question

Captcha Image
Reload

Note : Name and Email never shown.





Subscribe


Become a part of EducationForever. Subscribe to our FREE Newsletter