[C#] 기본상속_손녀 vitual override
페이지 정보
작성자 sbLAB 댓글 0건 조회 4,287회 작성일 18-07-25 17:27본문
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
btop bt = new btop();
bt.run1();
bt.show();
bt.print();
Console.ReadKey();
}
}
//부모클래스
class top
{
//virtual 을 선언하여 자식클래스에서 overiding 가능함을 알려줌
virtual public void run1()
{
Console.WriteLine("run1 입니다!");
}
}
//자식클래스(부모상속)
class ntop : top
{
//virtual - override
public override void run1()
{
Console.WriteLine("ntop run1 입니다!");
}
virtual public void show()
{
Console.WriteLine("ntop show 입니다!");
}
}
//손녀클래스(자식상속)
class btop : ntop
{
//virtual - override
public override void run1()
{
Console.WriteLine("btop run1 입니다!");
}
public override void show()
{
Console.WriteLine("btop show 입니다!");
}
public void print()
{
Console.WriteLine("btop print 입니다!");
}
}
}
댓글목록
등록된 댓글이 없습니다.