|
ms
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
diff between virtual and abstract?hello,
what is the difference to use the keyword virtual,abstract when we are overriding the methods.instead of abstract shall we use virtual everywhere when we need to override? i am little confusing to use these keywords. thaks.. If a subclass *needs* to override a member (i.e. you can't specify a
meaningful body in the base class, as it can't be defined), then it should be abstract in the base-class; if you just want to give the subclass the *ability* to override a method (if they want) then it should be virtual. Any abstract member forces the entire class to be abstract, which also means you can't create actuall instances of the base class, but you can of the superclass. Does that make sense? Marc chandu napisa³(a):
> hello, You must (sic!) override when you deriving from abstract class. You can > > what is the difference to use the keyword virtual,abstract when we are > overriding the methods.instead of abstract shall we use virtual everywhere > when we need to override? > i am little confusing to use these keywords. > > thaks.. > > override metods (if for some reason you need to do something else) when you deriving from virtual. ;) best, Slawomir chandu,
In some cases you cannot provide a implementation for some methods, but method have to be there because it is part of the class interface. You want the programmers using the class to provide this implementation and you don't want to let them instantiate objects of this class because without this method it won't simply work. In this case you declare the method and the class as abstract. Abstract classes cannot be instantiated because they are not complete. In other cases you can provide a default implementation of a method which is good enough to make the control work even if not re-defined, but you want to give the programmers using your class as a base class to provide their better implementation. In this case you declare the method as virtual thus, giving the progammers options whether to use the default or provide their own eomplementation or if they which to use the default and tweak the results. -- Show quoteHide quoteHTH Stoitcho Goutsev (100) "chandu" <nareshv_chan***@hotmail.com> wrote in message news:OlyJkkx0GHA.4016@TK2MSFTNGP02.phx.gbl... > hello, > > what is the difference to use the keyword virtual,abstract when we are > overriding the methods.instead of abstract shall we use virtual everywhere > when we need to override? > i am little confusing to use these keywords. > > thaks.. > |
|||||||||||||||||||||||