using System;
namespace Exam_Inherit2
{
//基类
public class Person
{
private string _name;//私有成员
private uint _age;//私有成员 public void GetInfo()//为了在类外访问
{
Console.WriteLine("请输入您的姓名和年龄");
_name=Console.ReadLine();
_age=uint.Parse(Console.ReadLine());
}
public void DispInfo()
{
Console.WriteLine("尊敬的{0},您的年龄是{1}",_name,_age);
}
}
//Person派生类的Student
public class Student:Person//使用:表示继承自基类
{
private string _school;
private uint _eng;
private uint _math;
private uint _com;//私有成员的访问权限
private uint _total;//总分 //获得学生的学校和成绩
public uint GetMarks()
{
Console.WriteLine("请输入您的学校");
_school=Console.ReadLine();
Console.WriteLine("请分别输入您的英语、数学、计算机的成绩");
_eng=uint.Parse(Console.ReadLine());
_math=uint.Parse(Console.ReadLine());
_com=uint.Parse(Console.ReadLine());
_total=_eng+_math+_com;
return _total;
}
private void DispMarks()
{
Console.WriteLine("您的总成绩是:{0}",_total);
}
}
//大学肄业生(没有毕业的学生)继承自学生类
//派生类是否可以继承基类的所有成员?
public class UnderGraduate:Student
{
public void ChkUp()
{
Console.WriteLine("要上升一级,要求总分不低于150分");
if(this.GetMarks()>149)
Console.WriteLine("合格,请升级!");
else
Console.WriteLine("不合格,不好意思,留级吧!");
}
}
public class Exam_Two
{
static void Main(string[]args)
{
UnderGraduate objUnderGraduate=new UnderGraduate();
objUnderGraduate.GetInfo();
objUnderGraduate.DispInfo();
//objUnderGraduate.DispMarks();
objUnderGraduate.ChkUp();
}
}
}
//如题,是否可以做其它一些测试?
namespace Exam_Inherit2
{
//基类
public class Person
{
private string _name;//私有成员
private uint _age;//私有成员 public void GetInfo()//为了在类外访问
{
Console.WriteLine("请输入您的姓名和年龄");
_name=Console.ReadLine();
_age=uint.Parse(Console.ReadLine());
}
public void DispInfo()
{
Console.WriteLine("尊敬的{0},您的年龄是{1}",_name,_age);
}
}
//Person派生类的Student
public class Student:Person//使用:表示继承自基类
{
private string _school;
private uint _eng;
private uint _math;
private uint _com;//私有成员的访问权限
private uint _total;//总分 //获得学生的学校和成绩
public uint GetMarks()
{
Console.WriteLine("请输入您的学校");
_school=Console.ReadLine();
Console.WriteLine("请分别输入您的英语、数学、计算机的成绩");
_eng=uint.Parse(Console.ReadLine());
_math=uint.Parse(Console.ReadLine());
_com=uint.Parse(Console.ReadLine());
_total=_eng+_math+_com;
return _total;
}
private void DispMarks()
{
Console.WriteLine("您的总成绩是:{0}",_total);
}
}
//大学肄业生(没有毕业的学生)继承自学生类
//派生类是否可以继承基类的所有成员?
public class UnderGraduate:Student
{
public void ChkUp()
{
Console.WriteLine("要上升一级,要求总分不低于150分");
if(this.GetMarks()>149)
Console.WriteLine("合格,请升级!");
else
Console.WriteLine("不合格,不好意思,留级吧!");
}
}
public class Exam_Two
{
static void Main(string[]args)
{
UnderGraduate objUnderGraduate=new UnderGraduate();
objUnderGraduate.GetInfo();
objUnderGraduate.DispInfo();
//objUnderGraduate.DispMarks();
objUnderGraduate.ChkUp();
}
}
}
//如题,是否可以做其它一些测试?
解决方案 »
- 真神奇,同样的正则和字符串,Groups[1]和Groups[组别名]返回结果就是差一点
- C#如何实现像按键精灵在屏幕找一张BMP格式的图片?并确定在屏幕上的位置?
- 发包中转器外包(SOCKET通讯程序)
- 关于控件位置的问题
- DataGridView1
- 谁有全国省市县的数据库 请给我一份 谢谢 QQ:44772414
- 有关 .NET Remoting 中 对象的生存期问题
- 究竟如何用HUFFMAN实现文本的压缩,仅探讨原理
- 所有值类型(如int,boolean)都是由Object继承而来的吗,一个是struct ,一个是class,在线中....
- 简单,字符串转换的问题?
- 请问高手如何禁止用户刷新页面!急!!!!!!!!!(在线等!!!)
- 求视图编写方法,要求按物资层次进行统计
1,在派生类中对基类成员的public属性进行访问,以间接访问基类的私有成员;
2,在基类中将私有成员定义为protected访问属性,以在派生类中直接对其进行访问;