C# Properties Aptitude Questions and Answers | Set 2

C# Properties Aptitude Questions | Set 2: This section contains aptitude questions and answers on C# Properties.
Submitted by Nidhi, on April 10, 2020

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?
  1. Declare empId property with both get and set accessors.
  2. Declare empId property with an only set accessor.
  3. Declare empId property with only get accessor.
  4. Declare empId property with getting, set and final accessors.

2) Can we create more than one property in a class in C#.NET?
  1. Yes
  2. No

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?
  1. Declare empId property with both get and set accessors.
  2. Declare empId property with an only set accessor.
  3. Declare empId property with only get accessor.
  4. Declare empId property with getting, set and final accessors.

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?
  1. Declare empId property with both get and set accessors.
  2. Declare empId property with an only set accessor.
  3. Declare empId property with only get accessor.
  4. Declare empId property with getting, set and final accessors.

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:

  1. Only A
  2. Only B
  3. B and C
  4. B, C, and D





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.