C#/수업 과제

클래스 및 인스턴스 만들기와 메서드 연습3 (SCV-배럭)

hyunjin-dev-log 2021. 12. 23. 17:17

메인메서드

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        SCV scv1 = new SCV();

        Barracks Barracks1 = scv1.Build("배럭");

        Console.WriteLine(Barracks1);
        Console.ReadLine();
    }
}

SCV 클래스

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class SCV
{
    //멤버 변수

    //생성자 메서드
    public SCV()
    {
        Console.WriteLine("SCV가 생성되었습니다.");
    }

    //멤버 메서드
    public Barracks Build(string name)
    {
        Console.WriteLine("{0}을 건설합니다.", name);
        return new Barracks();
    }
}

배럭 클래스

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Barracks
{
    //멤버 변수

    //생성자 메서드
    public Barracks()
    {
        Console.WriteLine("배럭이 건설되었습니다.");
    }

    //멤버 메서드
}

HelloWorld.exe
0.00MB