| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 446 人关注过本帖
标题:跪求高手...请问下面一代码那里错误了....
只看楼主 加入收藏
不要害怕俊杰
Rank: 1
等 级:新手上路
帖 子:15
专家分:1
注 册:2012-9-9
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:6 
跪求高手...请问下面一代码那里错误了....
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _2._12
{
    class Program
    {
        public class Student
        {
            private string m_name;
            private int m_grade;
            public string Name
            {
                get
                {
                    return m_name;
                }
                set
                {
                    this.m_name = value;
                }
            }
            public int Grade
            {
                get
                {
                    return m_grade;
                }
                set
                {
                    m_grade = value;
                }
            }
            public Student()
            {
                Grade = 1;
            }
            public abstract string Introduce();
       }
        public class Pupil : Student
        {
            public override string Introduce()
            {
                if (Grade >= 1 && Grade < 7)
                    return "This is an pupil of grade " + Grade;
                else
                    return "No such grade";
            }
        }
        public class Undergraduate : Student
        {
            public override string Introduce()
            {
                if (Grade > 0 && Grade < 5)
                    return "This is an undergraduate of grade" + Grade.ToString();
                else
                    return "No such grade";
            }
        }
        public class Graduate : Student
        {
            public override string Introduce()
            {
                if (Grade >= 1 && Grade < 4)
                    return "This is a graduate of grade " + Grade;
                else
                    return "No such grade";
            }
        }
        static void Main(string[] args)
        {
            Student student;
            Pupil pu = new Pupil();
            student = pu;
            pu.Grade = 5;
            Console.WriteLine(student.Introduce());
            Undergraduate un = new Undergraduate();
            student = un;
            un.Grade = 5;
            Console.WriteLine(student.Introduce());
            Graduate gr = new Graduate();
            student = gr;
            Console.WriteLine(student.Introduce());
            Console.WriteLine("按回车键结束");
            Console.Read();
        }
    }
}
报这个错误....Introduce()是抽象类但他包含了非抽象类....
跪求高手改正错误...
搜索更多相关主题的帖子: return public private 
2012-09-15 10:33
lybh24
Rank: 8Rank: 8
等 级:贵宾
威 望:19
帖 子:120
专家分:701
注 册:2012-9-8
收藏
得分:10 
抽象方法要包含在抽象类,你把你的 public class Student类改成: public abstract class Student,抽象类就行了

新群:273209143
2012-09-15 11:30
ZWYyj
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:9
帖 子:124
专家分:587
注 册:2012-8-10
收藏
得分:10 
有抽象方法的类必须被定义成抽象类,抽象类的继承者必须实现抽象方法,否则也必须被定义成抽象的,由下一个继承者实现,抽象类不能实例化对象。
 public abstract string Introduce();这个是抽象方法呀,所以你定义的student类必须为抽象类。
2012-09-15 14:55
不要害怕俊杰
Rank: 1
等 级:新手上路
帖 子:15
专家分:1
注 册:2012-9-9
收藏
得分:0 
回复 2楼 lybh24
谢谢...
2012-09-15 20:17
不要害怕俊杰
Rank: 1
等 级:新手上路
帖 子:15
专家分:1
注 册:2012-9-9
收藏
得分:0 
回复 3楼 ZWYyj
谢谢啦...
2012-09-15 20:17
跳过去
Rank: 8Rank: 8
等 级:贵宾
威 望:20
帖 子:282
专家分:976
注 册:2012-8-13
收藏
得分:0 
还真是用  Visual Studio 做开发啊

光棍中.....
2012-09-20 14:35
不要害怕俊杰
Rank: 1
等 级:新手上路
帖 子:15
专家分:1
注 册:2012-9-9
收藏
得分:0 
回复 6楼 跳过去
这个只是考试的题目啊...
2012-09-20 17:36
快速回复:跪求高手...请问下面一代码那里错误了....
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022301 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved