C#

210517 C#_class, 객체생성

S_pot 2021. 5. 17. 17:19
using System;

namespace _210517_007
{
    class Human
    {
        public double tall;        // 변수생성
        public void eat()          // 메서드생성
        {
            Console.WriteLine("냠냠냠...");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            int iNum;   // 기본형: int
            Human HumanObject;  // 기본형: 객체참조변수, 이것은 객체가 아니라 객체를 참조하는 변수, 위치만 가지고 있기 때문에 크기는 고정

            iNum = 100;

            HumanObject = new Human();  // HumaObject는 객체의 위치이고 new Human()은 객체를 생성한 것이다.(인스턴스 생성)
            HumanObject.tall = 1000;
            HumanObject.eat();
            Console.WriteLine("키 : " + HumanObject.tall);
        }
    }
}

 

출력값