Polymorphism in c#

using System;

namespace CSharpBasics
{
    class Polymorphism_bas
    {
        public string s_method()
        {
            return "base";
        }

        public virtual string s_method1() //Not mandatory to override a virtual method
        {
            return "base1";
        }
    }

    class Polymorphism_der : Polymorphism_bas
    {
        public string s_method()  //Eiether you can use new keyword or not..really doesn't matter just to used to shadow the base class functionality which nay ways is done.
        {
            return "der";
        }


        public string over_1(int i)
        {
            return "s";
        }

        public new string s_method1()
        {
            return "der1";
        }

        public void s_param(int i, params int[] arr)
        {
            Console.WriteLine("params = " + i.ToString() + " - " + arr.Length.ToString());
        }

        //ERROR - params has to be the last paramter in the list
        //public void s_param(int i, params int[] arr, int j)
        //{
        //    Console.WriteLine("params = " + i.ToString() + " - " + arr.Length.ToString());
        //}

        public void s_param(int i, int j)
        {
            Console.WriteLine("with out params = " + i.ToString() + " - " + j.ToString());
        }

        //public int over_1(int i) ERROR - Cannot have same method name with same parameter list and diff return type.
        //{
        //    return 1;
        //}

    }
}
Add Comments :

Login

Register