728x90
반응형
using static CSharp.Program;
namespace CSharp
{
//OOP(은닉성/상속성/다형성)
//자동차
//핸들 페달 차문
//전기장치 엔진 기름 <-> 외부 노출
class Car
{
//접근 한정자
//public protected private
private int energy;
public void SetEnergy(int energy)
{
this.energy = energy;
}
protected int price;
}
class SuperCar : Car
{
void Test()
{
price = 0;//protect는 자식 클래스에서 사용 가능
}
}
class Program
{
static void Main(string[] args)
{
Car car = new Car();
//car.energy;//오류
car.SetEnergy(100);
}
}
}
반응형