반응형
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | using System; using System.Collections.Generic; using System.Text; namespace 추상클래스 { // C#에서는 추상클래스에만 추상 메쏘드를 선언 가능 !! abstract class Person { public int age; // abstract --> virtual !! public abstract void Die(); // 순수 가상함수 !! public void Work() { } } class buddist : Person { public override void Die() { } } class Program { static void Main(string[] args) { // Person p = new Person(); // p.Die(); } } } // 추상 클래스와 인터페이스 !! // 같은점 // - 객체를 직접 생성 불가능 !! // - sealed 키워드?? 사용불가 !! // 다른점 !! // 1) 추상 클래스에는 일반적인 함수의 구현과 추상 메소드 둘다 가능하다 ! // -> 인터페이스에는 가상함수 가능하다 !! // 2) 인터페이스는 기본으로 public이다 !! // 3) 인터페이시는 인터페이스만 상속이 가능하다 !! abstract class Person { private int age; private string name; public abstract void work(); } interface IStudy { void Study(); } interface IEmp { void GetPay(); } class Pro : Person ,IEmp { public void GetPay() { throw new NotImplementedException(); } public override void work() { throw new NotImplementedException(); } } class Student : Person , IStudy { public void Study() { throw new NotImplementedException(); } public override void work() { throw new NotImplementedException(); } } |