C#교과서 마스터하기 34. 인터페이스(Interface)

min seung moon·2021년 7월 14일
0

C#

목록 보기
35/54

https://www.youtube.com/watch?v=N4u2yQji4ec&list=PLO56HZSjrPTB4NxAsEP8HRk6YKBDLbp7m&index=68

1. 인터페이스(Interface)

  • 클래스에서 반드시 구현해야 하는 관련 기능에 대한 정의가 포함된 개념
  • 특정 멤버가 반드시 구현되어야 함을 보증

2. 프로젝트

using System;
using static System.Console;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace testProject
{
    // 인터페이스
    public interface ICarStandard
    {
        void Left();
    }

    // 추상 클래스
    abstract class KS
    {
        public abstract void Back();
    }

    // 부분 클래스
    partial class MyCar : KS
    {
        public override void Back() => WriteLine("후진");
    }
    partial class MyCar
    {
        public void Right() => WriteLine("우회전");
    }

    // 봉인 클래스
    sealed class Car : MyCar, ICarStandard
    {
        public void Left() => WriteLine("좌회전");

        public void Run() => WriteLine("직진");
    }

    // class SpyCar : Car { }

    class Program
    {
        static void Main(string[] args)
        {
            Car car = new Car();
            car.Run();
            car.Right();
            car.Back();
            car.Left();
            // SpyCar spy = new SpyCar();
            // spy.Run();
        }
    }
}

profile
아직까지는 코린이!

0개의 댓글