コード例 #1
0
ファイル: Program.cs プロジェクト: alperenmehmet/OOP_csharp
        static void Main(string[] args)
        {
            Console.WriteLine("*****Iphone*****");
            Iphone iphone = new Iphone();

            iphone.Brand           = "Apple";
            iphone.Model           = "Iphone 12 Pro";
            iphone.UnitPrice       = "$999";
            iphone.Color           = "Silver";
            iphone.OperatingSystem = "IOS 14";

            Console.WriteLine($"Brand :{iphone.Brand}\nModel :{iphone.Model}\nUnit Price :{iphone.UnitPrice}\nColor :{iphone.Color}\nOperating System :{iphone.OperatingSystem}\nRing Sound:{iphone.PhoneRingSound()}");

            Console.WriteLine("\n*****Samsung*****");
            Samsung samsung = new Samsung();

            samsung.Brand           = "Samsung";
            samsung.Model           = "Galaxy S21 Ultra 5G";
            samsung.UnitPrice       = "$499.99";
            samsung.Color           = "Phantom Silver";
            samsung.OperatingSystem = "One UI 3.1, Android 11";

            Console.WriteLine($"Brand :{samsung.Brand}\nModel :{samsung.Model}\nUnit Price :{samsung.UnitPrice}\nColor :{samsung.Color}\nOperating System :{samsung.OperatingSystem}\nRing Sound:{samsung.PhoneRingSound()}");

            Console.WriteLine("\n*****Nokia*****");
            Nokia nokia = new Nokia();

            nokia.Brand     = "Nokia";
            nokia.Model     = "3310";
            nokia.UnitPrice = "Not available.";
            nokia.Color     = "Silver";
            //nokia.OperatingSystem = "";   If you can go to Nokia.cs, you will see there is no OperatingSystem in Nokia.cs...
            Console.WriteLine($"Brand :{nokia.Brand}\nModel :{nokia.Model}\nUnit Price :{nokia.UnitPrice}\nColor :{nokia.Color}\nOperating System :{""}\nRing Sound:{nokia.PhoneRingSound()}");
            Console.ReadLine();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            // ==== Inheritance - Tính Kế Thừa ====
            // is-a relationship
            Samsung S8 = new Samsung();

            S8.Name = "Samsung Galaxy S8";
            // S8.OS = "Android";
            S8.Call();
            System.Console.WriteLine(S8.OS);
            IPhone iphone7 = new IPhone();

            iphone7.Siri();
            System.Console.WriteLine(iphone7.OS);
            // ==== Polymorphism - Tính Đa Hình ====
            S8.Text();
            iphone7.Text();
            // handle data
            Smartphone phone1 = new Samsung();

            phone1.Call();
            Smartphone phone2 = new IPhone();

            phone2.Call();
            Smartphone[] dataArray = new Smartphone[] { phone1, phone2 };
            // ==== Abstract Class ====
            Cat kitty = new Cat();

            kitty.MakeSound();
        }
コード例 #3
0
        static void Main()
        {
            /* Apple apple = new Apple();
             * apple.MobileStandardEmployee();
             * apple.Call();
             * Samsung samsung = new Samsung();
             * samsung.Call();*/
            //run time polymorphism or Dynamic polymorphism
            MobileStandard mobileStandard;

            mobileStandard = new Apple();
            mobileStandard.Call(); //call Method in Apple
            Console.WriteLine(mobileStandard.Terms());
            mobileStandard = new Samsung();
            mobileStandard.Call(); //Call Method in samsung
            Console.WriteLine(mobileStandard.Terms());
            Console.Read();
        }
コード例 #4
0
ファイル: AbstractEg.cs プロジェクト: nikb15/git4864
        // creating an abstract class this abstract class must now make object as subch
        static void Main()
        {
            /*
             * Methods 1
             *  Apple ap = new Apple();
             *          ap.Call();
             */
            MobileStandart mobileStandart;

            mobileStandart = new Apple();
            mobileStandart.Call(); // Will talk about Aple

            mobileStandart = new Samsung();
            mobileStandart.Call(); // call out for samsungs


            mobileStandart.Term(); // will show samsung terms
            Console.ReadLine();
        }