Sponsored Ad

Wednesday, June 1, 2011

Can we have Non Abstract Method in Abstract Class in C#

Yes, you can have non abstract methods in abstract class. Along with non abstract methods you can also have abstract methods in abstract class.

You can not directly use non abstract methods of abstract class, for the same you have to derive a class from abstract class and give new implementation of non abstract method in derived class.

In below example there is abstract class abstract_class_example which is having the non abstract method non_abstract_method_example.

 

using System;

namespace MyApp
{
    public class abstract_examples
    {
        public static void Main(string[] args)
        {
            Console.ReadLine();
        }

        //abstract class with non abstract methods
        public abstract class abstract_class_example
        {
            public void non_abstract_method_example()
            {
                Console.WriteLine("Non Abstract Method Example.");
            }
        }     
    }
}

No comments:

Post a Comment

Sponsored Ad

Followers

Follow Us