//¹®Á¦ 4. ´ÙÀ½ ÇÁ·Î±×·¥ÀÇ Ãâ·ÂÀ» ¾²½Ã¿À. using System; namespace Test4 { class X { protected int x; public X(int x) { this.x = x; } public virtual void foo() { Console.WriteLine(x); } } class Y : X { int y; public Y(int x1,int x2) : base(x1) { y = x2; } public override void foo() { Console.WriteLine(y); base.foo(); } } class Z : X { int z; public Z(int x1,int x2) : base(x1) { z = x2; } public override void foo() { Console.WriteLine(z); base.foo(); } } class Program { static void Main(string[] args) { int[] data = { 1, 2, 3, 4, 5 }; X []arr = new X[3]; arr[0] = new X(data[0]); arr[1] = new Y(data[1],data[2]); arr[2] = new Z(data[3],data[4]); for (int i = 0; i < arr.Length; i++) arr[i].foo(); } } }