Exemple #1
0
        static void Main(string[] args)
        {
            FlyingCar car = new FlyingCar();

            car.Run();
            car.Fly();

            IRunnable runnble = car as IRunnable;
            IFlyable  flyable = car as IFlyable;

            runnble.Run();
            flyable.Fly();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            // 다중 상속받은 클래스
            FlyingCar car = new FlyingCar();

            car.Run();
            car.Fly();
            car.Company = "현대";

            // 부모 인터페이스
            // 부모연산자인 IRunnable에 as 연산자를 사용하여 자식 클래스인 car에 캐스팅 하였다.
            IRunnable runnable = car as IRunnable;

            runnable.Run();

            IFlyable flyable = car as IFlyable;

            flyable.Fly();
        }
Exemple #3
0
        static void Main(string[] args)
        {
            FlyingCar car = new FlyingCar();

            car.Run();
            car.Fly();
            car.Company = "현대";

            IRunnable runnable = car as IRunnable;  //형변환 안되면 null값 들어감

            runnable.Run();

            IFlyable flyable = car as IFlyable;

            flyable.Fly();

            IWalkable walkable = car as IWalkable;

            walkable.Run();
        }
Exemple #4
0
        static void Main(string[] args)
        {
            FlyingCar car = new FlyingCar();

            car.Run();
            car.Fly();

            IRunnable runnable = car as IRunnable; // 이미 구현했기때문에 as IRunnable 생략가능

            runnable.Run();

            IFlyable flyable = car as IFlyable;

            flyable.Fly();

            Testclass test = new Testclass();

            IRunnable run = test as IRunnable;

            test.Run();
            IWalkAble walk = test as IWalkAble;

            test.walk();
        }