15

I have read about virtual methods in C#. Is there any concept called virtual class in C#? Is abstract class in C# and virtual class in C++ the same?

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
Tejus
  • 694
  • 1
  • 7
  • 19
  • 4
    What do you mean by a virtual class in C++? Do you mean virtual inherentance or a class with a pure virtual function? – shf301 Feb 27 '13 at 04:23

3 Answers3

19

There is no such thing in C# - and it's really not necessary since multiple implementation inheritance is not supported. Making a class abstract really only means that you cannot create instances of that class and they might not be fully implemented (e.g. might contain abstract methods).

BrokenGlass
  • 158,293
  • 28
  • 286
  • 335
7

There are no virtual classes in C#. Abstract class is not the same since you cannot instantiate an abstract class.

You can do the opposite of marking something virtual by marking it sealed, which prevents it from being inherited.

si618
  • 16,580
  • 12
  • 67
  • 84
3

I will opine with a link to this earlier SO post: In C++ what is a virtual base class?

As others have mentioned, since C# does not have multiple inheritance, the need to have a "virtual base class" that limits multiple inheritance is not needed, hence it does not apply to C#. Only members in C# can be virtual.

Community
  • 1
  • 1
Isaiah Nelson
  • 2,450
  • 4
  • 34
  • 53