Thursday, February 23, 2012

Abstract Classes and Abstract Members

A class declared as abstract can never be instantiated. Instead, only its concrete
subclasses can be instantiated.
Abstract classes are able to define abstract members. Abstract members are like virtual
members, except they don’t provide a default implementation. That implementation
must be provided by the subclass, unless that subclass is also declared

public abstract class Asset
    // Note empty implementation
    public abstract decimal NetValue { get; }
public class Stock : Asset
    public long SharesOwned;
    public decimal CurrentPrice;
    // Override like a virtual method.
    public override decimal NetValue
        get { return CurrentPrice * SharesOwned; }



No comments:

Post a Comment