using System;
public class DemoEncap {
// private variables declared
// these can only be accessed by
// public methods of class
private String studentName;
private int studentAge;
// using accessors to get and
// set the value of studentName
public String Name
{
get
return studentName;
}
set
studentName = value;
// set the value of studentAge
public int Age
return studentAge;
studentAge = value;
// Driver Class
public class GFG {
// Main Method
static public void Main()
// creating object
DemoEncap obj = new DemoEncap();
// calls set accessor of the property Name,
// and pass "Ankita" as value of the
// standard field 'value'
obj.Name = "Ankitai";
// calls set accessor of the property Age,
// and pass "21" as value of the
obj.Age = 21;
// Displaying values of the variables
Console.WriteLine("Name: " + obj.Name);
Console.WriteLine("Age: " + obj.Age);