C# - Properties MCQ Questions and Answers

Practice Mode
Showing 10 of 30 questions
Q11
What is the main purpose of properties in C#?
  • A To replace methods completely
  • B To provide controlled access to class fields
  • C To make all fields public
  • D To replace constructors
Answer: Option B
Explanation: Properties provide controlled access to private fields through get and set accessors.
Q12
Which of the following is an auto-implemented property?
  • A public int Age { get; set; }
  • B public int Age { get { return age; } set { age = value; } }
  • C private int age; public int Age { get { return age; } }
  • D public int GetAge() { return age; }
Answer: Option A
Explanation: Auto-implemented properties have simplified syntax without explicit backing fields.
Q13
What is a read-only property in C#?
  • A A property with only set accessor
  • B A property with only get accessor
  • C A property with both get and set
  • D A static property
Answer: Option B
Explanation: Read-only properties have only get accessor and cannot be modified externally.
Q14
Which access modifier is commonly used for property setters to make properties read-only?
  • A public
  • B private
  • C protected
  • D internal
Answer: Option B
Explanation: Private setters allow internal modification while preventing external changes.
Q15
What is the purpose of the "value" keyword in property setters?
  • A It represents the current object
  • B It represents the property value being assigned
  • C It represents the default value
  • D It represents the base class
Answer: Option B
Explanation: The value keyword represents the data being assigned to the property.
Q16
Which property type allows both get and set operations?
  • A Read-only property
  • B Write-only property
  • C Read-write property
  • D Static property
Answer: Option C
Explanation: Read-write properties have both get and set accessors.
Q17
What is a static property in C#?
  • A A property that cannot be changed
  • B A property that belongs to the class itself
  • C A property that is automatically implemented
  • D A property that is read-only
Answer: Option B
Explanation: Static properties belong to the class rather than specific instances.
Q18
Which property has only a set accessor?
  • A Read-only property
  • B Write-only property
  • C Read-write property
  • D Static property
Answer: Option B
Explanation: Write-only properties are rare but useful for specific scenarios like passwords.
Q19
What is the default accessibility of get and set accessors in properties?
  • A They are always public
  • B They have the same accessibility as the property
  • C They are always private
  • D They are always protected
Answer: Option B
Explanation: Accessors inherit the property accessibility unless specified otherwise.
Q20
Which keyword is used to create calculated properties?
  • A return
  • B calculate
  • C get
  • D compute
Answer: Option C
Explanation: Calculated properties compute values rather than storing them directly.
Questions and Answers for Competitive Exams Various Entrance Test