using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Encapsulation
{
class Encaps
{
private int x, y = 0;
public int RETURNX
{
get
{
return x;
}
set
{
if (value > 300)
{
x = value;
}
}
}
public int RETURNY
{
get
{
return y;
}
set
{
if (value > 300)
{
y = value;
}
}
}
}
class Program
{
static void Main(string[] args)
{
Encaps obj = new Encaps();
obj.RETURNX = 44;
obj.RETURNY = 322;
Console.WriteLine(obj.RETURNX);
Console.WriteLine(obj.RETURNY);
Console.ReadLine();
}
}
}
/*this is a simple example whuich demonstrates the concept of encapsulation
*
* we are using the private members of the class through public properties
*
* output:
* 0
* 322
*
*/
No comments:
Post a Comment