Sponsored Ad

Wednesday, June 1, 2011

Can a Class can be Derived from Abstract Class in C#

Yes, you can derive a class from abstract class the code is given below. write a abstract class with abstract function and drive a class from this abstract class and override the abstract method in derive class and give implementation. while calling this method you need to create instance of derive class only because parent class don't have any implementation.

Program Output

Code to derive a class from abstract class:

using System;

namespace MyApp
{
    public class abstract_derived_class
    {
        public static void Main(string[] args)
        {
            derived_class obj = new derived_class();
            obj.my_method();

            Console.ReadLine();
        }

        public abstract class abstract_class
        {
            public abstract void my_method();          
        }

        public class derived_class : abstract_class
        {
            public override void my_method()
            {
                Console.WriteLine("Derived Class Method.");
            }
        }
    }
}

0 comments:

Post a Comment

Sponsored Ad

Related Interview Questions



Followers

Follow Us