Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Abstract class without any abstract method

Tags:

c#

I am surprised to know that an abstract class in C# is possible with no abstract methods also.

abstract class AbstractDemo
{
 public void show()
  {
    Console.WriteLine("In Show Method"); 
   }
}
class MainDemo:AbstractDemo
{
 public static void Main()
 {
    Console.WriteLine("In Main Method");
 }
}

Any explaination ?

like image 708
Mohammad Nadeem Avatar asked Aug 09 '10 10:08

Mohammad Nadeem


1 Answers

Sometimes you don't want to give the possibility to instantiate a class but you need this class as a base class for other classes.

The reason for choosing abstract classes over interfaces is that you can provide some basic implementation.

like image 133
Itay Karo Avatar answered Oct 11 '22 17:10

Itay Karo