Is overriding of a function possible in the same class?

Is overriding of a function possible in the same class?

It is typically not possible to override a method in the same class as overriding is a concept of inheritance which exposes the child class functionalities rather than base class. Hence it has to be in child class.

However, C# does support method overriding, but only if explicitly requested using the modifiers override and virtual. When overriding one method with another, the signatures of the two methods must be identical and must have the same visibility. Using these modifiers, class methods, indexers, properties and events can all be overridden in C#.

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.