Re: A text from a book which must be wrong(virtual, abstract metod)

Tech-Archive recommends: Fix windows errors by optimizing your registry



Tony Johansson <johansson.andersson@xxxxxxxxx> wrote:
I'm reading in a book about C# and here is something that sound strange.

"You can override a virtual method (or accessor) with an abstract method (or
abstract accessor) in a derived class.Any classes derived from this abstract
class must override these abstract methods and provide new implamantations
for them to become non-abstract."

What override a virtual method (or accessor) with an abstract method ??
This must be wrong??

It's easy enough to show that it's correct:

public class Base
{
public virtual void Foo()
{
}
}

public abstract class Derived : Base
{
public abstract override void Foo();
}

Basically it's saying, "Derived is rejecting the implementation of Foo
in Base - it's not optional to override it in classes derived from
Derived, you *have* to override it."

--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
.



Relevant Pages

  • Re: The Override Problem
    ... >> occasionally override. ... >> get the method signature off by a hair. ... > JBuilder provides an "override method" wizard which can insert stubs ... > for all inherited abstract methods and can insert stubs for selected ...
    (comp.lang.java.programmer)
  • A text from a book which must be wrong(virtual, abstract metod)
    ... I'm reading in a book about C# and here is something that sound strange. ... abstract accessor) in a derived class.Any classes derived from this abstract ... class must override these abstract methods and provide new implamantations ... What override a virtual method with an abstract method ?? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: "Virtual properties behave like abstract methods" ?
    ... Except for differences in declaration and invocation syntax, virtual, ... sealed, override, and abstract accessors behave exactly like virtual, ... sealed, override and abstract methods. ... Virtual properties behave like abstract methods, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: inherting from CollectionBase
    ... Sort of. ... When you type "override" within the class body and press ... CollectionBase - it has default implementations for all its methods. ... For a class with abstract methods, or an interface, you can also ...
    (microsoft.public.dotnet.languages.csharp)
  • Abstract Class Theory
    ... If we were to define all abstract methods in an abstract class, ... and then override the heretofore 'abstract' ... Derived classes from abstract base classes must overrided the abstract ... method defininition anyway, so why not just provide a complete definition ...
    (microsoft.public.dotnet.languages.csharp)