Abstract methods in non-abstract classes, on the contrary

What is the purpose of defining non-abstract methods in abstract classes and abstract methods in non-abstract classes?

What, where are useful scripts for using them?

+3
source share
4 answers
  • You cannot declare a method abstractin a non-abstract class. From the C # spec:

    10.6.6 Abstract Methods

    (...) Abstract method declarations are allowed only in abstract classes (§10.1.1.1).

  • A non-abstract method in a class abstractis a method that should not (or sometimes even cannot) be overridden in derived classes.

    , ( virtual) , ( virtual).

    , ( - ).

+3

, , . .

.

+1

?

An abstract class declaring nothing but abstract methods is slightly different than an interface declaration; typically, an abstract class includes some minimal / non-executable default functionality, leaving abstract stubs for things that depend on the implementation.

... and abstract methods in non-abstract classes?

You cannot declare abstract methods in a non-abstract class.

+1
source

in this case, define your method as Virtual, not Abstract.

+1
source

All Articles