what is a virtual in c#

Posted by jmls on 09-Apr-2010 12:41

what is the ABL equivalent of this c# statement ?

public virtual bool IsMarshallAware()

Is it PROTECTED ?

if so, what os

protected virtual bool IsMarshallAware() ??

All Replies

Posted by Peter Judge on 09-Apr-2010 13:11

From http://msdn.microsoft.com/en-us/library/9fkccyh4(VS.80).aspx : "the virtual keyword is used to modify a method, property, indexer or event declaration, and allow it to be overridden in a derived class."

-- peter

Posted by Matt Baker on 09-Apr-2010 13:24

If something is not marked as virtual you can still override it by adding the "new" keyword to the overriding method in the derived class.  It is mutually exclusive with final which means you cannot override it at all.

But don't try because it introduces a weird scenarios where your "new" override of the method is not called if the data type of variable that is being accessed (from the caller) is declared as the base class.  Instead the CLR invokes the base class' implementation of the method.   This doesn't happen if the variable from the caller is a reference to an interface. (It is amazing the subtleties that will bite you if you don't understand them).

For ABL "virtual" doesn't have any meaning.  ABL acts more like java for this, in that if some method is public or protected you can override it simply by providing the override keyword.

So the ABL equivalent of the first is:

method public logical IsMarshallAware():

end method.

And if you want to override it in a derived class:

method public override logical IsMarshallAware():

end method.

For the second there is no difference except the access modifier:

method protected logical IsMarshallAware():

end method.

This thread is closed