RamSelva:
hello friend
In Real time appln. based on which parameter do we need to opt either Virtual or Abstract function in C#?I just want to know the diff b/w virtual/override and abstract/override?Any diff other than that abstract can't be instantiated..
Hello RamSelva,
Virtual functions can have implementation but Abstract function cannot have implementation
Sample Code
public abstract class Base{
public virtual double virtualMethod() {
return 0;
}
public abstract string abstractMethod {
// Should Have Implementation in the derived class
get;
}
}
public class Derived: Base {
public override string abstractMethod {
get { return "abstractMethod"; }
}
}
public class Test {
public static void main() {
Derived d = new Derived();
d.abstractMethod // Returns "abstractMethod"
d.virtualMethod(); //(Returns 0 )if the
//virtual method is overiden in the derived class it will call the overiden method only
}
}