C#/C# Concept

[C#] 상속

군우 2018. 4. 5. 10:24
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ConsoleApplication13
{
    class Program
    {
        static void Main(string[] args)
        {
            Father f = new Father();
            f.SayGrandFather();
            f.SayFather();
        }
    }
    public class GrandFather
    {
        public GrandFather()
        {
            Console.WriteLine("I am a GrandFather's constructor");
        }
 
        public void SayGrandFather()
        {
            Console.WriteLine("SayGrandFather()");
        }
    }
 
    public class Father: GrandFather
    {
        public Father()
        {
            Console.WriteLine("I am a Father's constructor");
        }
 
        public void SayFather()
        {
            Console.WriteLine("SayFather()");
        }
    }
}
 
cs