Click here to Skip to main content
15,039,244 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
how to implement non abstract method in derived class?
Posted

All the non-abstract members of the abstract class are simply inherited. And these methods can be accessed as of any child class would access the parent class methods .

http://stackoverflow.com/questions/2026095/how-to-access-functions-from-abstract-class-without-making-them-static[^]
   
You don't have to - if it isn't an abstract method, then you don;t have to implement it, because it already has an implementation in the base class.
If you want to replace a non-abstract method, then you can "hide" the original by declaring the method as new in the derived class:
C#
abstract class A
    {
    public abstract void xxx(int i);
    public void yyy(int i) { }
    }
class B : A
    {
    public override void xxx(int i) {}
    public new void yyy(int i) { }
    }

Or if it is marked correctly in the base class, you can use override:
C#
abstract class A
    {
    public abstract void xxx(int i);
    public virtual void yyy(int i) { }
    }
class B : A
    {
    public override void xxx(int i) {}
    public override void yyy(int i) { }
    }
   
There are two cases, depending on the very nature of the base class method, namely if it is:
  1. virtual, then you are free to override it.
  2. 'standard' (that is NOT virtual), then you could hide it using the new keyword, but it is not advisable (see, for instance: "Is it possible to override a non-virtual method?" at Stack Overflow[^]).
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900