C # interface

 1 //Public interface: "Animals" 

2 public interface IAnimal
3 {
4 void Behavior(); //behavior methods, describing the characteristics of various animals
5 }
6
7 //Class: Dog
8 public class Dog: IAnimal
9 {
10 public void Behavior()
11 {
12 Console.WriteLine(name() + " I sleep at night and be active during the day");
13 }
14 string name()
15 {
16 return "dog";
17 }
18 }
19
20 //Class: Cat
21 public class Cat: IAnimal
22 {
23 string info = "Cat";
24 public void Behavior()
25 {
26 Console.WriteLine(info + "I sleep during the day and be active at night") ;
27 }
28 }
29 //Simple application:
30 static void Main(string[] args)
31 {
32 IAnimal myDog = new Dog();
33 myDog.Behavior(); //< span style="color: #008000;">Output: "Dog I sleep at night and move around during the day"
34 IAnimal myCat = new Cat();
35 myCat.Behavior(); //< span style="color: #008000;">Output: "Cat I sleep during the day and be active at night"
36
37 }

 1 //Public interface: "Animals" 

2 public interface IAnimal
3 {
4 void Behavior(); //behavior methods, describing the characteristics of various animals
5 }
6
7 //Class: Dog
8 public class Dog: IAnimal
9 {
10 public void Behavior()
11 {
12 Console.WriteLine(name() + " I sleep at night and be active during the day");
13 }
14 string name()
15 {
16 return "dog";
17 }
18 }
19
20 //Class: Cat
21 public class Cat: IAnimal
22 {
23 string info = "Cat";
24 public void Behavior()
25 {
26 Console.WriteLine(info + "I sleep during the day and be active at night") ;
27 }
28 }
29 //Simple application:
30 static void Main(string[] args)
31 {
32 IAnimal myDog = new Dog();
33 myDog.Behavior(); //< span style="color: #008000;">Output: "Dog I sleep at night and move around during the day"
34 IAnimal myCat = new Cat();
35 myCat.Behavior(); //< span style="color: #008000;">Output: "Cat I sleep during the day and be active at night"
36
37 }

Leave a Comment

Your email address will not be published.