43. 클래스(Class)
==> 클래스.cs
using System;
public class 클래스
{
// Entry Point
public static void Main()
{
// Car클래스의 인스턴스 생성
Car car = new Car(); // 새로운 실체(객체)
car.Color = "Red";
car.Run();
// Human 클래스 사용
Human h = new Human();
h.Name = "홍길동";
h.Age = 21;
h.Show();
// StaticClass's Instance
StaticClass.Name = "백";
StaticClass s = new StaticClass();
s.Age = 21;
}
}
==============================================================================================
==> Car.cs
using System;
// Class
public class Car
{
// Field : 나중에 private으로.
public string Color; // 나중에 소문자로...
// Method
public void Run()
{
Console.WriteLine("{0}색 자동차가 달리다", Color);
}
}
// Class
public class Human
{
public string Name; //Field
public int Age; // Field
public void Show() { // Method
Console.WriteLine("{0}, {1}", Name, Age);
}
}
public class StaticClass
{
// static: 정적접근가능
public static string Name; // Field
// x : 인스턴스접근 : 객체생성후
public int Age; // Member Variable
}