110,534
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication10
{
abstract public class Animal //首先,你那里的class类都拼错了
{
public string A_name;
public string A_Type;
public Animal() //加上0参数的构造函数
{ }
public Animal(string name)
{
A_name = name;
A_Type = "动物";
}
public virtual string Getname()
{
Console.WriteLine("当前的动物是{0},名字是{1}", A_name, A_Type);
return this.A_name;
}
}
class Dog : Animal
{
public Dog() //父类没有0参数的构造函数,子类出现0参数构造函数会报错
{
A_Type = "狗";
}
public Dog(string name) //必须有一个参数的构造函数,否则Animal doudou = new Dog("豆豆"); 这就错了
{
A_Type = name;
}
public override string Getname()
{
return base.Getname(); //这里必须加上return 否则,你只是取得base.Getname的值,却没返回
}
}
class Program
{
static void Main(string[] args)
{
Animal doudou = new Dog("豆豆");
doudou.Getname();
}
}
}
大哥啊,我知道我很小白,您攻击我、骂我无所谓,可是您指点了大方向让我去看书之后,能不能给我讲讲我这个程序呢?我的C#书已经看了一半了,看了八个章节了,总得调试小程序吧 看书去吧
看书去吧