C#

클래스 연습2

s0002 2023. 1. 4. 22:06

using System;
using System.Collections.Generic;
using System.Text;

namespace Study03
{
    class App
    {
        public App()
        {
            Slime slime = new Slime();

            slime.Eat();
            slime.CreatePlort();
            slime.Like();
        }
    }
}
using System;
using System.Collections.Generic;
using System.Text;

namespace Study03
{
   
    class Slime
    {
        //멤버 변수
        string food = "과일";
        string spawnArea = "모든 지역";
        string favoriteToy = "비치볼";
        int value = 7;

        //생성자
        public Slime()
        {
            Console.WriteLine("슬라임이 생성되었습니다");
            Console.WriteLine("먹이:{0}\n스폰지역:{1}\n좋아하는 장난감:{2}\n가치:{3}",food,spawnArea,favoriteToy,value);
        }
        //멤버 메소드
        public void Eat()
        {
            Console.WriteLine("{0}를 먹었습니다",food);
        }
        public void Like()
        {
            Console.WriteLine("{0}을 좋아합니다", favoriteToy);
        }
        public void CreatePlort()
        {
            Console.WriteLine("플로트를 생성합니다. 가치는 {0}입니다", value);
        }
    }
}

'C#' 카테고리의 다른 글

클래스 연습4  (0) 2023.01.04
클래스 연습3  (0) 2023.01.04
클래스 연습1  (0) 2023.01.04
클래스 연습(벌처)  (0) 2023.01.04
메서드 연습4  (0) 2023.01.04