locked
Cannot implicitly convert type 'Testng.Maruti' to 'Testng.Toyota'. An explicit conversion exists (are you missing a cast?) RRS feed

  • Question

  •  

    Hi,

    I am getting the following error in C# code while executing the below code "Cannot implicitly convert type 'Testng.Maruti' to 'Testng.Toyota'. An explicit conversion exists (are you missing a cast?)" .

     

     

    namespace Testng
    {
        class Program
        {
            static void Main(string[] args)
            {
                try
                {
                    Toyota t =new Maruti();
                    t.print1();
                    t.print();
                    Console.Read();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);

                }

            }
        }

        abstract class Car
        {
            public abstract void print();

        }

        public class Maruti
        {
          
            public void print1()
            {
                Console.WriteLine("It is Maruti SX4");

            }

        }
        public class Toyota : Maruti
        {
            //Toyota()
            //{
            //    Console.WriteLine("It is Toyota Class");

            //}
            public void print()
            {
                Console.WriteLine("It is Maruti Corrola");

            }

        }

    }

     

     

    Please advise why we can't reference using child class .

     

    Regards,

    Amit

     

     


    Wednesday, September 7, 2011 11:10 AM