NET岛

导航

面向对象

重载运算符
public static type operator op (Argument1[,Argument2])     //op:  +  - ...
{
    //...
}

定义接口
public interface IDrivable
{
    int lenth
    {
         get;
         set; //省略为只读
    } 
    int total();
    event System.EventHandler OutOfFuel; //事件
}

使用接口
Truck myTruck = new Truck();

IDrivable myVehicle;
myVehicle = (IDrivable)myTruck;

实现接口
public class Truck : IDrivable
{
    //...

    //显式实现,拥有与接口定义相同的访问级别
    int IDrivable.total()
    {
         //....
    }
}

不能被继承的类
public sealed class Aclass
{
    //....
}

重写基类成员
//基类
public virtual void go()
{
}
//继承类
public override void go()
{
}

//如果成员不能被重写,就只能被隐藏
internal new int myMethod()
{
}

对象被访问的类型取决于变量声明的类型
覆盖或隐藏成员应注意维持其兼容性

可以用base.访问基类成员

抽象类 abstract

posted on 2005-08-21 23:05  左佩玉  阅读(329)  评论(0编辑  收藏  举报