1) Suppose we have a class Employee, that contains a property called "empId", we want it cannot be changed during the program, and then what needs to do in our program?
- Declare empId property with both get and set accessors.
- Declare empId property with an only set accessor.
- Declare empId property with only get accessor.
- Declare empId property with getting, set and final accessors.
Correct answer: 3
Declare empId property with only get accessor.
To protect from modification, we need to implement only to get accessor.
2) Can we create more than one property in a class in C#.NET?
- Yes
- No
Correct answer: 1
Yes
Yes, we can create multiple properties; we can create properties for each data member of a class.
3) Suppose we have a class Employee that contains a property called "empId", we want to provide functionality for reading and write both, and then what needs to do in our program?
- Declare empId property with both get and set accessors.
- Declare empId property with an only set accessor.
- Declare empId property with only get accessor.
- Declare empId property with getting, set and final accessors.
Correct answer: 1
Declare empId property with both get and set accessors.
To create a read and write property, we need to use set and get accessors in our program.
4) Suppose we have a class Employee, that contains a property called "empId", we want to make it write-only, and then what needs to do in our program?
- Declare empId property with both get and set accessors.
- Declare empId property with an only set accessor.
- Declare empId property with only get accessor.
- Declare empId property with getting, set and final accessors.
Correct answer: 2
Declare empId property with an only set accessor.
To create a write-only property, we need to use only set accessor in our program.
5) Suppose we have a class Employee that contains a property called "empId" with set and get accessors then which of the following options work properly?
A. Employee.empId = 101;
B. Employee emp = new Employee(); emp.empId = 101;
C. Employee emp = new Employee(); int id = emp.empId;
D. Employee emp = new Employee(); emp.empId = emp.empId + 10;
Options:
- Only A
- Only B
- B and C
- B, C, and D
Correct answer: 4
B, C, and D
The statements B, C and D work properly according to question.