读书人

一个面向对象的面试题。该如何处理

发布时间: 2012-01-19 00:22:28 作者: rapoo

一个面向对象的面试题。
动物有bite的行为,请用面试对象的继承机制写出狗bite猫的行为。

各位,这是一外资公司的面试题,大家写写看。

[解决办法]
public abstract class Animal
{
bool Bite( Animal another );
}

//
public class Dog : Animal
{

public override bool Bite( Animal another )
{
return true ;
}

}

//
public class Cat : Animal
{

public override bool Bite( Animal another )
{
return false ;
}

}

//

Dog dog = new Dog();
Cat cat = new Cat();

bool result = dog.Bite( cat );


读书人网 >asp.net

热点推荐