1.Abstract method are those which are not defined. Means if your method doesnt have its body it is abstract.
On the other hand, if you have already defined the body and want the classes that derives it can override its member, if they wish, you define it as virtual.
The VB.NET equivalent to these keywords gives a clear knowledge on this :
abstract ==
virtual ==
3.Abstract method are by default empty.
Abstract method must be override in all derived classes.
A class in which Abstract method have must be abstract.
Eg- Abstract void Getdata();
It must be end with (;) in Abstract class.
Virtual method may or may not have body by default.
Virtual method may or may not be override it depends on user.
Eg- Virtual void Getdata() {..........}
On the other hand, if you have already defined the body and want the classes that derives it can override its member, if they wish, you define it as virtual.
The VB.NET equivalent to these keywords gives a clear knowledge on this :
abstract ==
MustOverride
virtual ==
Overridable
2.
An Abstract method must be override in child classes where as virtual method is not compulsory to override.An abstract method doesn't have implementation detail where as virtual method has it.
only abstract class can haveabstract method, any class can have virtual method3.Abstract method are by default empty.
Abstract method must be override in all derived classes.
A class in which Abstract method have must be abstract.
Eg- Abstract void Getdata();
It must be end with (;) in Abstract class.
Virtual method may or may not have body by default.
Virtual method may or may not be override it depends on user.
Eg- Virtual void Getdata() {..........}
Abstract | Virtual | No Keyword | |
Can have implementation? | No | Yes | Yes |
Can override? | Must | Can but not a must | You can declare a new method with the same name |
Which keyword to use to provide new implementation in the concrete class? | override | override | No keyword needed |
If an object is created of the base class type, which method will be executed? | Concrete implementation | The parent implementation will be called only if no implementation is provided in the concrete class | Parent implementation |
If an object is created of the concrete class type, which method will be executed? | Concrete implementation | Concrete implementation | The parent implementation will be called only if no implementation is provided in the concrete class |
No comments:
Post a Comment