[c#] inheritance practice3

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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ConsoleApplication3
{
    class GrandParent
    {
        public string FirstName;
        public string LastName;
 
        public GrandParent(string last_name)
        {
            LastName = last_name;
        }
    }
 
 
    class Parent : GrandParent
    {
 
        //base : 부모클래스를 가리키는 것임
        //그래서, 부모클래스의 생성자에 파라메터가 있으면, 자식클래스의 생성자에 : base(파라메터)  를 명시해줘야한다.
        //왜냐하면, 자식이 부모클래스를 상속받은경우, 실행순서가 부모클래스 생성자가 먼저 실행되고 자식클래스 생성자가 실행되기 때문임
        public Parent() : base("KIM")
        {
 
        }
    }
 
    class Child : Parent
    {
        public Child()
        {
 
        }
    }
 
    
    class Program
    {
        static void Main(string[] args)
        {
            Parent p = new Parent();
 
            Console.WriteLine(p.LastName);
 
            Console.ReadLine();
        }
    }
 
}
 
 
cs

댓글

이 블로그의 인기 게시물

[c#] DataTable을 dataGridView에 바인딩

[React] index.html 수정하기

[React] 프로젝트 생성