-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInterfaces.cs
74 lines (60 loc) · 1.61 KB
/
Interfaces.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
namespace hello_world {
//interfaces
public interface IDetails {
public int Age {get; set;}
public string Name {get; set;}
public int myAge();
public string myName();
}
public interface IHola {
public string Message {get; set;}
public void Hola();
}
//implementer class
public class Person : IDetails, IHola {
public int Age {get; set;}
public string Name {get; set;}
public string Message {get; set;}
//new property
public bool OnlyMe {get; set;}
public Person(int age, string name , string message) {
this.Age = age;
this.Name = name;
this.Message = message;
}
public int myAge() {
return Age;
}
public string myName() {
return Name;
}
public void Hola() {
Console.WriteLine($"{Message}");
}
//new method
public void NewMethod() {
Console.WriteLine("Only i can do this!");
}
}
//client class
public class DemoInterfaces {
public DemoInterfaces() {
this.demo();
}
public void demo() {
Person adarsh = new Person(20, "Adarsh", "Welcome to C# world!");
IDetails arpit = new Person(10, "Arpit", "Grow up kido!");
IHola ankur = new Person(25, "Ankur", "Hmm :/");
adarsh.Hola();
Console.WriteLine($"{adarsh.myAge()}, {adarsh.myName()}");
adarsh.NewMethod();
Console.WriteLine($"{arpit.myAge()}, {arpit.myName()}");
//arpit.Hola(); error
//arpit.NewMethod(); error
//Console.WriteLine($"{ankur.myAge()}, {ankur.myName()}") error
ankur.Hola();
// ankur.NewMethod();
}
}
}