투케이2K

47. (C#/NET) [Mac Os] [문법] 인터페이스 (interface) 구현 및 메소드 재사용 수행 본문

C샵 (NET)

47. (C#/NET) [Mac Os] [문법] 인터페이스 (interface) 구현 및 메소드 재사용 수행

투케이2K 2024. 3. 15. 14:27
반응형

[개발 환경 설정]

개발 언어 : C# / NET

 

[소스 코드]

using System;
using System.Collections;
using Microsoft.VisualBasic;

namespace testProject {


    // [인터페이스 생성]
    public interface Application{

        // [멤버 앞에 접근제한자 사용 안함]
        void onCreate();
    }





    // [클래스 생성]
    public class Activity : Application { // [인터페이스 상속]

        // [인터페이스 메소드 구현]
        public void onCreate(){
            Console.WriteLine($"");
            Console.WriteLine($"------------------------------------------");
            Console.WriteLine($"[Activity] : [onCreate] : [Log]");
            Console.WriteLine($"------------------------------------------");
            Console.WriteLine($"Activity onCreate");
            Console.WriteLine($"------------------------------------------");
            Console.WriteLine($"");
        }
    }



    // [프로그램 동작 클래스]
    class Program {

        static void Main(string[] args){
            
            /*
            -------------------------------------------
            [요약 설명]
            -------------------------------------------
            1. 인터페이스 (interface) : 구체적인 함수 내용을 구현하지 않고, 단지 정의 (prototype definition) 만을 사용합니다
            -------------------------------------------
            2. 인터페이스 (interface) 는 메소드 재사용을 위해 주로 사용됩니다
            -------------------------------------------
            3. 하나의 클래스에서는 여러개의 인터페이스를 가질 수 있습니다
            -------------------------------------------
            4. C# 에서 인터페이스는 interface 라는 키워드를 사용해 정의합니다
            -------------------------------------------
            */

            // [클래스 생성]
            Activity activity = new Activity();


            // [메소드 호출]
            activity.onCreate();

        }

    }

}
 

[결과 출력]


반응형
Comments