抽象类和接口的区别(4)
时间:2025-04-05
时间:2025-04-05
区别抽象类与接口
public class Person : ISwim
{
public void Swim()
{
//Swimming in person's style.
}
}
public class Frog : ISwim
{
public void Swim()
{
//Swimming in frog's style.
}
}
public class Fish : ISwim
{
public void Swim()
{
//Swimming in fish's style.
}
}
1. 共性大于个性
2. 共性相同的个体间必然具有相同的属性与行为
3. 相同行为的实现方式具有一定区别
abstract public class Fish
{
abstract public void Swim();
}
public class 鲫鱼 : Fish
{
public override void Swim()
{
//Swim like a 鲫鱼
}
}
public class 鲤鱼 : Fish
{
public override void Swim()
{
//Swim like a 鲤鱼
}
}
public class 金鱼 : Fish
{
public override void Swim()
{
//Swim like a 金鱼
}
}
观察在使用接口或是使用抽象基类的几条理由中,第三条理由其实是一样的,它所描述的是
上一篇:争先创优心得体会
下一篇:《软件开发流程实训教程》第4章