public static void Print(RDoctor x)
        {
            x.Print();
            int sal = x.GetSalary();

            if (sal <= 20000)
            {
                Console.WriteLine("Pay by check");
            }
            else
            {
                Console.WriteLine("Pay by cash");
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            RDoctor    r = new RDoctor("Mr.Samaram", "6969696969", 30000);
            Consultant c = new Consultant("Sherman", "98764504", 5, 2000);

            Print(r);
            Print(c);
            Doctor r2 = new RDoctor("Samram 2", "55445333", 116);

            // The above line was possible because the object reference of base class can point to an
            // derived class object.(The universal truth is Derived class IS A Base class)
            r2.Print();
            // Now runs correctly
        }
        static void Main(string[] args)
        {
            RDoctor    r = new RDoctor("Mr.Samaram", "6969696969", 30000);
            Consultant c = new Consultant("Sherman", "98764504", 5, 2000);

            Print(r);
            Print(c);
            Doctor r2 = new RDoctor("Samram 2", "55445333", 116);

            // The above line was possible because the object reference of base class can point to an
            // derived class object.(The universal truth is Derived class IS A Base class)
            r2.Print();
            // The above r2.Print() calls the print from class doctor but not RDoctor. To overcome this
            // problem and combine below two overloaded methods we use Runtime Polymorphism
        }