Complete the code to declare a private field in a class.
private int [1];The keyword private makes the field accessible only inside the class. Here, age is the field name.
Complete the code to create a public method that returns the private field value.
public int GetAge() {
return [1];
}The method returns the private field age. Using age directly returns its value.
Fix the error in the setter method to correctly assign the value to the private field.
public void SetAge(int value) {
[1] = value;
}The private field age should be assigned the incoming value. Using age = value; correctly updates the field.
Fill both blanks to create a property that encapsulates the private field.
public int Age {
get { return [1]; }
set { [2] = value; }
}The property Age uses the private field age inside both getter and setter to encapsulate access.
Fill all three blanks to complete the class with encapsulation for the age field.
class Person { private int [1]; public int [2] { get { return [3]; } set { [3] = value; } } }
The private field age is encapsulated by the public property Age. The property uses the field age in its getter and setter.