[c#] interface practice
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
/// <summary>
/// interface를 만든다
/// </summary>
interface TV
{
//Boolean onoff; //error!! 인터페이스는 필드를 포함할 수 없음
//public void Record(); //error!! 인터페이스는 한정자를 사용할 수 없음
void TurnOn();
void TurnOff();
}
/// <summary>
/// interface를 장착한다
/// </summary>
class MYTV:TV
{
//인터페이스는 반드시 구현해야함. 구현하지 않으면 에러임!
public void TurnOn()
{
Console.WriteLine("Turn On the TV");
}
public void TurnOff()
{
Console.WriteLine("Turn Off the TV");
}
}
class Program
{
static void Main(string[] args)
{
MYTV myTv = new MYTV();
myTv.TurnOn();
myTv.TurnOff();
Console.ReadLine();
}
}
}
| cs |
댓글
댓글 쓰기