-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
48 lines (41 loc) · 1.15 KB
/
Program.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
public interface ICarDriveProperties{
void Drive();
}
// Writing interfaces
public interface ICarStopProperties{
void Stop();
}
public class Car1 : ICarDriveProperties{
public void Drive(){
Console.WriteLine("Car1 is driving"); // Car1 can just drive
}
}
public class Car2 : ICarStopProperties{
public void Stop(){
Console.WriteLine("Car2 is stopping"); // Car 2 can just stop
}
}
public class Car3 : ICarDriveProperties , ICarStopProperties{
public void Drive(){
Console.WriteLine("Car3 is driving");
}
// Car 3 can drive and stop
public void Stop(){
Console.WriteLine("Car3 is stopping");
}
}
class Program{
static void Main(string[] args){
var car1 = new Car1();
var car2 = new Car2();
var car3 = new Car3();
car1.Drive();
car2.Stop();
car3.Drive(); // Valid Operations
car3.Stop();
/*
car1.Stop();
car2.Drive(); // Example invalid operations
*/
}
}