본문 바로가기
c# 입문

[c#] c# 상속성

by javaman 2022. 7. 9.

객체 지향 프로그래밍의 큰 특징

상속성  /   은닉성 /    다형성

 

 

1. 상속성

 

 

using System;

namespace Class
{
    
    class Program
    {
        //부모 클래스
        class Player
        {
            public int hp;
            public int attack;

            public Player(int hp)
            {
                this.hp = hp;

            }
        }

        //자식 클래스
        class Mage : Player
        {
            public Mage() : base(100)
            {
                attack = 20;//부모 클래스의 필드 변수에 접근 가능

            }
        }
        
     
        static void Main(string[] args)
        {

        }
    }
}