-
Notifications
You must be signed in to change notification settings - Fork 0
/
MehotdOverriding.cs
53 lines (42 loc) · 1.05 KB
/
MehotdOverriding.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
/* Encapsulation:
* Encapsulate the wrapping the data and code.
* variable of class are always hidden from other class
* it can be only access using the method of their classes.
*/
namespace TestApplication
{
public class Demo
{
private int _x;
private int _y;
public Demo(){
}
public Demo(int i,int j)
{
_x = i;
_y = j;
}
public void ShowXy()
{
Console.WriteLine("{0}{1}", _x, _y);
}
public static Demo operator +(Demo d1, Demo d2)
{
var demo = new Demo {_x = d1._x + d2._y, _y = d1._x + d2._y};
return demo;
}
}
public static class Program
{
public static void Main(string[] args)
{
var demo = new Demo();
demo.ShowXy();
var demo1 = new Demo( 20,30);
demo1.ShowXy();
var demo2 = demo + demo1;
demo2.ShowXy();
}
}
}