반응형
using System;
using System.Collections.Generic;
using System.Text;

namespace 생성자
{
    class Person
    {
        private string name; 
        public Person()
        {
            Console.WriteLine("Person()");
        }
        public Person(string name)
        {
            Console.WriteLine(name); 
        }
    }
    class BitStudent : Person
    {   
        // C# 생성자 :  객체 초기화하는 함수 !!  
        // 1) 인스턴스 생성자 : 객체가 만들어질때 불려지는 생성자 !!
        public static string InstructorName;  
        public BitStudent()
        {
            Console.WriteLine("BitStudent()");
          
        }
        //2) 정적 생성자 :  static 생성자 !! 
        //  클래스가 메모리에 로딩될때 호출되어지는 생성자 !!
        // --> 무조건 1번만 호출이 된다 !! 
        static BitStudent()
        {   // 스태틱 멤버에 대한 초기화 !! 
            InstructorName = "Jang";
        }

        // base: C#에서 부모 클래스를 의미한다 !!    
        // this() :  자기 클래스의 다른 생성자를 의미한다 !! 
        public BitStudent(string name) : this()
        {
          //  this.name = name; 
            Console.WriteLine(name);
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
          // BitStudent bit = new BitStudent("홍길동");
            Console.WriteLine(BitStudent.InstructorName);
        }
    } 


}

'C#' 카테고리의 다른 글

[C#] 이벤트  (0) 2014.11.18
[C#] 예외처리  (0) 2014.11.18
[C#] 상속  (0) 2014.11.18
[C#] 배열  (0) 2014.11.18
[C#] 델리게이트 (Delegate)  (0) 2014.11.18

+ Recent posts