-
03/17 인터페이스 연습 1C#/수업내용 2021. 3. 17. 12:38
Program.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Study06 { class Program { static void Main(string[] args) { Console.WriteLine("Main"); new App(); } } }
App.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Study06 { public class App { public App() { Valkyrie valkyrie = new Valkyrie(); valkyrie.Attack(); Wraith wraith = new Wraith(); wraith.Cloaking(); wraith.Attack(); } } }
TerranUnit.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Study06 { public class TerranUnit { public TerranUnit() { Console.WriteLine("{0}가 생성되었습니다.", this.GetType().Name); } public virtual void Attack() { Console.WriteLine("가 공격했습니다."); } } }
ICloaking.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Study06 { interface ICloaking { void Cloaking(); } }
Valkyrie.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Study06 { public class Valkyrie : TerranUnit { public Valkyrie() { } public override void Attack() { Console.Write(this.GetType().Name); base.Attack(); } } }
Wraith.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Study06 { public class Wraith : TerranUnit, ICloaking { public Wraith() { } public override void Attack() { Console.Write(this.GetType().Name); base.Attack(); } public void Cloaking() { Console.WriteLine("{0}가 클로킹했습니다.", this.GetType().Name); } } }
'C# > 수업내용' 카테고리의 다른 글
03/17 abtract 연습 (0) 2021.03.17 03/17 인터페이스연습 2 (0) 2021.03.17 03/17 List<T> 변수 선언, 인스턴스 생성, 값 할당, 출력 복습 2 (0) 2021.03.17 03/17 배열 변수 선언, 인스턴스 생성, 값 할당, 출력 복습 2 (0) 2021.03.17 03/17 Dictionary 변수 선언, 인스턴스 생성, 값 할당, 출력 복습 (0) 2021.03.17