C#
클래스 연습3
s0002
2023. 1. 4. 22:41
using System;
using System.Collections.Generic;
using System.Text;
namespace Study03
{
class App
{
public App()
{
Cat cat = new Cat();
cat.Move();
cat.Eat();
cat.Betamed("집사");
cat.Attack("쥐");
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Study03
{
class Cat
{
//멤버 변수
public string species = "페르시안";
int life = 10;
float size = 0.7f;
//생성자
public Cat()
{
Console.WriteLine("고양이가 생성되었습니다");
Console.WriteLine("종:{0}\n생명력:{1}\n크기:{2}", species, life, size);
}
//멤버 메서드
public void Move()
{
Console.WriteLine("고양이가 이동합니다");
}
public void Attack(string target)
{
Console.WriteLine("고양이가 {0}을(를) 공격합니다",target);
}
public void Eat()
{
Console.WriteLine("고양이가 생선을 먹습니다");
}
public void Betamed(string butler)
{
Console.WriteLine("고양이가 {0}에게 길들여졌습니다",butler);
}
}
}