<p>Why wouldn't I choose abstract? What are the limitations to declaring a class member virtual? Can only methods be declared virtual?</p>

[{'answer_id': 81059, 'author': 'Maximilian', 'author_id': 1733, 'author_profile': 'https://Stackoverflow.com/users/1733', 'pm_score': 0, 'selected': False, 'text': "<p>If you want to give it an implementation in your base class you make it virtual, if you don't you make it abstract.</p>\n\n<p>Yes, only methods can be declared virtual.</p>\n"}, {'answer_id': 81064, 'author': 'Phil Wright', 'author_id': 6276, 'author_profile': 'https://Stackoverflow.com/users/6276', 'pm_score': 2, 'selected': False, 'text': '<p>You would use abstract if you do not want to define any implementation in the base class and want to force it to be defined in any derived classes. Define it as a virtual if you want to provide a default implementatio that can be overriden by derived classes.</p>\n\n<p>Yes, only methods can be virtual.</p>\n'}, {'answer_id': 81090, 'author': 'Seb Rose', 'author_id': 12405, 'author_profile': 'https://Stackoverflow.com/users/12405', 'pm_score': 0, 'selected': False, 'text': "<p>Abstract means that you can't provide a default implementation. This in turn means that all subclasses must provide an implementation of the abstract method in order to be instantiable (concrete).</p>\n\n<p>I'm not sure what you mean by 'limitations', so can't answer that point.</p>\n\n<p>Properties can be declared virtual, but you can conceptually think of them as methods too.</p>\n"}, {'answer_id': 81093, 'author': 'Richard Szalay', 'author_id': 3603, 'author_profile': 'https://Stackoverflow.com/users/3603', 'pm_score': 2, 'selected': False, 'text': '<p>A member should be declared virtual if there is a base implementation, but there is a possibility of that functionality being overridden in a child class. Virtual can also be used instead of abstract to allow a method implementation to be optional (ie. the base implementation is an empty method)</p>\n\n<p>There is no limitation when setting a member as virtual, but virtual members are slower than non-virtual methods.</p>\n\n<p>Both methods and properties can be marked as virtual.</p>\n'}, {'answer_id': 81167, 'author': 'Sakin', 'author_id': 12818, 'author_profile': 'https://Stackoverflow.com/users/12818', 'pm_score': 0, 'selected': False, 'text': "<p>First of all, I will answer you second question. Only methods can be declared virtual.\nYou would choose virtual instead of abstract when you want some default functionality in your base class, but you want to leave the option of overriding this functionality by classes that inherit from your base class.\nFor examples:</p>\n\n<p>If you are implementing the <strong>Shape</strong> class, you would probably have a method called <strong>getArea()</strong> that returns the area of your shape. In this case, there's no default behavior for the getArea() method in the Shape class, so you would implement it as <strong>abstract</strong>. Implementing a method as abstract will prevent you to instantiate a <strong>Shape</strong> object.</p>\n\n<p>On the other hand, if you implement the class <strong>Dog</strong>, you may want to implement the method <strong>Bark()</strong> in this case, you may want to implement a default barking sound and put it in the <strong>Dog</strong> class, while some inherited classes, like the class <strong>Chiwawa</strong> may want to override this method and implement a specific barking sound. In this case, the method bark will be implemented as <strong>virtual</strong> and you will be able to instantiate Dogs as well as Chiwawas.</p>\n"}, {'answer_id': 81171, 'author': 'Kokuma', 'author_id': 12088, 'author_profile': 'https://Stackoverflow.com/users/12088', 'pm_score': 4, 'selected': True, 'text': '<p>An abstract method or property (both can be virtual or abstract) can only be declared in an abstract class and cannot have a body, i.e. you can\'t implement it in your abstract class.</p>\n\n<p>A virtual method or property must have a body, i.e. you must provide an implementation (even if the body is empty).</p>\n\n<p>If someone want to use your abstract class, he will have to implement a class that inherits from it and explicitly implement the abstract methods and properties but can chose to not override the virtual methods and properties.</p>\n\n<p>Exemple :</p>\n\n<pre><code>using System;\nusing C=System.Console;\n\nnamespace Foo\n{\n    public class Bar\n    {\n        public static void Main(string[] args)\n        {\n            myImplementationOfTest miot = new myImplementationOfTest();\n            miot.myVirtualMethod();\n            miot.myOtherVirtualMethod();\n            miot.myProperty = 42;\n            miot.myAbstractMethod();\n        }\n    }\n\n    public abstract class test\n    {\n        public abstract int myProperty\n        {\n            get;\n            set;\n        }\n\n        public abstract void myAbstractMethod();\n\n        public virtual void myVirtualMethod()\n        {\n            C.WriteLine("foo");\n        }\n\n        public virtual void myOtherVirtualMethod()\n        {\n        }\n    }\n\n    public class myImplementationOfTest : test\n    {\n        private int _foo;\n        public override int myProperty\n        {\n            get { return _foo; }\n            set { _foo = value; }\n        }\n\n        public override void myAbstractMethod()\n        {\n            C.WriteLine(myProperty);\n        }\n\n        public override void myOtherVirtualMethod()\n        {\n            C.WriteLine("bar");\n        }\n    }\n}\n</code></pre>\n'}, {'answer_id': 81239, 'author': 'Benjol', 'author_id': 11410, 'author_profile': 'https://Stackoverflow.com/users/11410', 'pm_score': 1, 'selected': False, 'text': '<p>There is a gotcha here to be aware of with Windows Forms.</p>\n\n<p>If you want a Control/UserControl from which you can inherit, even if you have no logic in the base class, you don\'t want it abstract, because otherwise you won\'t be able to use the Designer in the derived classes:\n<a href="http://www.urbanpotato.net/default.aspx/document/2001" rel="nofollow noreferrer">http://www.urbanpotato.net/default.aspx/document/2001</a></p>\n'}, {'answer_id': 81935, 'author': 'Hallgrim', 'author_id': 15454, 'author_profile': 'https://Stackoverflow.com/users/15454', 'pm_score': 0, 'selected': False, 'text': '<p>You question is more related to style than technicalities. I think that this book\n<a href="https://rads.stackoverflow.com/amzn/click/com/0321246756" rel="nofollow noreferrer" rel="nofollow noreferrer">http://www.amazon.com/Framework-Design-Guidelines-Conventions-Development/dp/0321246756</a>\nhas great discussion around your question and lots of others.</p>\n'}, {'answer_id': 91235, 'author': 'Chris Canal', 'author_id': 5802, 'author_profile': 'https://Stackoverflow.com/users/5802', 'pm_score': 0, 'selected': False, 'text': "<p>I personally mark most methods and properties virtual.  I use proxies and lazy loading alot, so I don't want to have to worry about changing things at a later date.</p>\n"}]
['https://Stackoverflow.com/questions/81052', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/6651/']