CSharp - What is the output: abstract class with no abstract method

Question

Can you compile the following code?

You have marked your class abstract but there is no abstract method in it, like this:

abstract class MyAbstractClass
{
        protected int myInt = 25;
        //public abstract void ShowMe();
        public virtual void CompleteMethod1()
        {
            Console.WriteLine("MyAbstractClass.CompleteMethod1()");
        }
        public void CompleteMethod2()
        {
            Console.WriteLine("MyAbstractClass.CompleteMethod2()");
        }
}


Click to view the answer

Yes.

Note

It will compile but you must remember that you cannot create an object for this class.

So, if you code like this:

MyAbstractClass absRef = new MyAbstractClass();//Error

We cannot create objects from an abstract class.

An abstract class has virtually no use if it is not extended.

Related Quiz