日期:2014-05-17  浏览次数:20895 次

完全小白,急求大神指点第一个小程序
这是我的第一个程序,所以我的问题对于大神来讲可能是弱智型的或是不可理喻型的,但还望大神能够不吝赐教,指出错误,帮忙改正,谢了!!!

我的第一个程序是这样的,我想先定义一个抽象类Animal作为基类,基类里有两个域名字和类型一个Animal的构造函数,还有一个虚方法Getname;
Dog类是Animal的派生类,派生类有一个自己的构造函数,并重新覆盖了基类的虚方法Getname;
在主函数中,我实例化一个名为doudou的对象,然后调用Getname;

以下是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication10
{
class Program
{
abstract public calss Animal
{
public string A_name;
public string A_Type;
public Animal(string name)
{ A_name=name;
A_Type="动物";
}
public virtual string Getname(){
Console.WriteLine("当前的动物是{0},名字是{1}",A_name,A_Type);
return A_name;}
}
class Dog:Animal{
public Dog(){
A_Type="狗";}
public override string Getname(){
base.Getname();
}
}
static void Main(string[] args)
{
Animal doudou=new Dog("豆豆");
doudou.Getname();
}
}
}



以下是错误的信息:
错误 1 应为 get 或 set 访问器 第12行 
错误 2 应输入 } 第11行 
错误 3 方法必须具有返回类型 第14行 
错误 4 应输入 class、delegate、enum、interface 或 struct 第29行 
错误 5 应输入标识符 第29行
错误 6 应输入 class、delegate、enum、interface 或 struct 第29行
错误 7 应输入 class、delegate、enum、interface 或 struct C 第31行
错误 8 应输入类型、命名空间定义或文件尾 第34行 
错误 9 应输入类型、命名空间定义或文件尾 第35行 



哎,真的很想弄明白怎么回事,大神啊,救救我吧

------解决方案--------------------
具体错误已经指出,希望你写代码还是细心点,单词拼错就是自己问题。编译出错,要学会查找错误。

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;