https://www.youtube.com/watch?v=kkKLpwowinc&list=PLO56HZSjrPTB4NxAsEP8HRk6YKBDLbp7m&index=66
using System;
using static System.Console;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace testProject
{
// 자동차 관련 부모 클래스
class Car
{
public void Go() => WriteLine("달리다");
}
// Car의 자식 클래스
class Benz : Car
{
}
class Tesla : Car
{
}
class Program : Object
{
static void Main(string[] args)
{
(new Benz()).Go();
(new Tesla()).Go();
}
}
}
using System;
using static System.Console;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace testProject
{
// 열거형
public enum CarType { EV, ICEV }
class Car
{
public void Go() => WriteLine("달리다");
}
// Car의 자식 클래스
class Benz : Car
{
public CarType Style { get; private set; }
public Benz()
{
Style = CarType.ICEV;
}
public Benz(CarType carType)
{
Style = carType;
}
}
class Tesla : Car
{
public CarType Style { get; set; }
public Tesla()
{
Style = CarType.EV;
}
public Tesla(CarType carType)
{
Style = carType;
}
}
class Program : Object
{
static void Main(string[] args)
{
Benz benz = new Benz();
benz.Go();
WriteLine(benz.Style);
Tesla tesla = new Tesla();
tesla.Go();
WriteLine(tesla.Style);
}
}
}
using System;
using static System.Console;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace testProject
{
// 열거형
public enum CarType { EV, ICEV }
// 추상 클래스
public abstract class CarBase
{
public abstract void Left(); // 추상 메서드, 본문X, 시그니처O => 표준(강제) => 인터페이스
public void Back() => WriteLine("후진하다");
}
class Car : CarBase
{
public CarType Style { get; private set; }
public void Go() => WriteLine("달리다");
// 추상화 재정의
public override void Left() => WriteLine("좌회전하다");
public Car(CarType carType)
{
Style = carType;
}
}
// Car의 자식 클래스
class Benz : Car
{
public Benz() : this(CarType.ICEV){}
public Benz(CarType carType) : base(carType) { }
}
class Tesla : Car
{
public Tesla() : this(CarType.EV) { }
public Tesla(CarType carType) : base(carType) { }
}
class Program : Object
{
static void Main(string[] args)
{
Benz benz = new Benz();
benz.Go();
benz.Back();
benz.Left();
WriteLine(benz.Style);
Tesla tesla = new Tesla();
tesla.Go();
tesla.Back();
tesla.Left();
WriteLine(tesla.Style);
}
}
}
using System;
using static System.Console;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace testProject
{
// 열거형
public enum CarType { EV, ICEV }
// 추상 클래스
public abstract class CarBase
{
public abstract void Left(); // 추상 메서드, 본문X, 시그니처O => 표준(강제) => 인터페이스
public void Back() => WriteLine("후진하다");
}
class Car : CarBase
{
public CarType Style { get; private set; }
public void Go() => WriteLine("달리다");
// 추상화 재정의
public override void Left() => WriteLine("좌회전하다");
public Car(CarType carType)
{
Style = carType;
}
}
// Car의 자식 클래스
class Benz : Car
{
public Benz() : this(CarType.ICEV){}
public Benz(CarType carType) : base(carType) { }
}
class Tesla : Car
{
public Tesla() : this(CarType.EV) { }
public Tesla(CarType carType) : base(carType) { }
}
// 봉인 클래스(최종)
sealed class Future : Car
{
public Future() : this(CarType.EV) { }
public Future(CarType carType) : base(carType) { }
public new void Go()
{
base.Go();
WriteLine("날다");
}
}
class OtherFuture : Future
{
}
class Program : Object
{
static void Main(string[] args)
{
Benz benz = new Benz();
benz.Go();
benz.Back();
benz.Left();
WriteLine(benz.Style);
Tesla tesla = new Tesla();
tesla.Go();
tesla.Back();
tesla.Left();
WriteLine(tesla.Style);
Future future = new Future();
future.Go();
}
}
}
using System;
using static System.Console;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace testProject
{
// 열거형
public enum CarType { EV, ICEV }
// 추상 클래스
public abstract class CarBase
{
public abstract void Left(); // 추상 메서드, 본문X, 시그니처O => 표준(강제) => 인터페이스
public void Back() => WriteLine("후진하다");
}
class Car : CarBase
{
public void Go() => WriteLine("달리다");
// 추상화 재정의
public override void Left() => WriteLine("좌회전하다");
}
// Car의 자식 클래스
class Benz : Car
{
public CarType Style { get; private set; }
public Benz()
{
Style = CarType.ICEV;
}
public Benz(CarType carType)
{
Style = carType;
}
}
class Tesla : Car
{
public CarType Style { get; set; }
public Tesla()
{
Style = CarType.EV;
}
public Tesla(CarType carType)
{
Style = carType;
}
}
class Program : Object
{
static void Main(string[] args)
{
Benz benz = new Benz();
benz.Go();
benz.Back();
benz.Left();
WriteLine(benz.Style);
Tesla tesla = new Tesla();
tesla.Go();
tesla.Back();
tesla.Left();
WriteLine(tesla.Style);
}
}
}
using System;
using static System.Console;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace testProject
{
// 열거형
public enum CarType { EV, ICEV }
// 추상 클래스
public abstract class CarBase
{
public abstract void Left(); // 추상 메서드, 본문X, 시그니처O => 표준(강제) => 인터페이스
public void Back() => WriteLine("후진하다");
protected string LeftMessage { get; private set; } = "좌회전하다";
}
class Car : CarBase
{
public CarType Style { get; private set; }
public void Go() => WriteLine("달리다");
// 추상화 재정의
public override void Left() => WriteLine(LeftMessage);
public Car(CarType carType)
{
Style = carType;
}
}
// Car의 자식 클래스
class Benz : Car
{
public Benz() : this(CarType.ICEV){}
public Benz(CarType carType) : base(carType) { }
}
class Tesla : Car
{
public Tesla() : this(CarType.EV) { }
public Tesla(CarType carType) : base(carType) { }
}
// 봉인 클래스(최종)
sealed class Future : Car
{
public Future() : this(CarType.EV) { }
public Future(CarType carType) : base(carType) { }
public new void Go()
{
base.Go();
WriteLine("날다");
}
}
class Program : Object
{
static void Main(string[] args)
{
Benz benz = new Benz();
benz.Go();
benz.Back();
benz.Left();
WriteLine(benz.Style);
Tesla tesla = new Tesla();
tesla.Go();
tesla.Back();
tesla.Left();
WriteLine(tesla.Style);
Future future = new Future();
future.Go();
}
}
}
using System;
using static System.Console;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace testProject
{
// 열거형
public enum CarType { EV, ICEV }
// 추상 클래스
public abstract class CarBase
{
public abstract void Left(); // 추상 메서드, 본문X, 시그니처O => 표준(강제) => 인터페이스
public void Back() => WriteLine("후진하다");
}
class Car : CarBase
{
public CarType Style { get; private set; }
public void Go() => WriteLine("달리다");
// 추상화 재정의
public override void Left() => WriteLine("좌회전하다");
public Car(CarType carType)
{
Style = carType;
}
}
// Car의 자식 클래스
class Benz : Car
{
public Benz() : this(CarType.ICEV){}
public Benz(CarType carType) : base(carType) { }
}
class Tesla : Car
{
public Tesla() : this(CarType.EV) { }
public Tesla(CarType carType) : base(carType) { }
}
class Future : Car
{
public Future() : this(CarType.EV) { }
public Future(CarType carType) : base(carType) { }
public new void Go()
{
base.Go();
WriteLine("날다");
}
}
class Program : Object
{
static void Main(string[] args)
{
Benz benz = new Benz();
benz.Go();
benz.Back();
benz.Left();
WriteLine(benz.Style);
Tesla tesla = new Tesla();
tesla.Go();
tesla.Back();
tesla.Left();
WriteLine(tesla.Style);
Future future = new Future();
future.Go();
}
}
}