c#测试题,跪求大佬 20
using System;
namespace test
{
public abstract class Animal
{
public virtual void eating(){}
public virtual void showing(){}
public virtual void running(){}
}
public class Cat : Animal
{
public override void eating()
{
Console.WriteLine("猫吃老鼠");
}
public override void showing()
{
Console.WriteLine("喵喵叫");
}
public override void running()
{
Console.WriteLine("轻轻地走");
}
}
class Class1
{
static void Main(string[] args)
{
Cat xiaohua = new Cat();
xiaohua.eating();
xiaohua.showing();
xiaohua.running();
}
}
}
public abstract class Animal
{
public virtual void eating(){
Console.write("吃");
};
public virtual void showing(){
Console.write("自我介绍");
};
public virtual void running(){
Console.write("跑");
};
}
@2:cat(猫)继承Animal(动物)类,java中是用关键字extends,C#中直接在类名后用冒号":"就表示继承,例:
public class Cat : Animal{
public override void eating(){
Console.write("猫吃老鼠");
};
public override void showing(){
Console.write("喵喵叫");
};
public override void running(){
Console.write("轻轻地走");
};
}
@3:
public static void Main(string[] args)
{
Cat xiaohua=new Cat();
xiaohua.eating();
xiaohua.showing();
xiaohua.running();
}