⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 9-2.cs

📁 java基础方面的一些实例代码
💻 CS
字号:
//程序9-2
using System;
namespace School
{
	public class Student 
	{
		protected string studName;
		protected	int studID;
		public Student()
		{  }
		public Student(string str, int id)
		{
			studName=str;
			studID=id;
		}
		public void PrintBase()
		{
			Console.WriteLine("在基类: Student.");
		}
		public void FindInfo(int id)
		{
			if(id==studID)
			   Console.WriteLine ("{0}is a student. ", studName);
		}
	} 
	public class CollegeStudent :Student
	{        
		string department; 
		new string  studName; 
		public CollegeStudent ( string deptmnt,string str,string bStudName, int id )
		{
			department=deptmnt;
			studName=str;
			studID=id;
			base.studName=bStudName;
		}
		public void PrintDerived()
		{
			Console.WriteLine("在派生类: CollegeStudent.");
		}
		public  new void FindInfo(int id)
		{
			if(id==studID)
			   Console.WriteLine ("{0}is a student in the {1} Department. ", studName,department);
		}
		public  void FindInfo2(int id)
		{
			if(id==studID)
			   Console.WriteLine ("{0}is a student in the {1} Department. ", base.studName,department);
		}
		public   void FindInfo3(int id)
		{
			if(id==studID) base.FindInfo( id);
		}
	}
	public class Test
	{
		public static void Main()
		{
			Student AStudent = new Student("李四",0518277);
			CollegeStudent ACollegeStudent=new CollegeStudent ("计算机","张三", "王二",0518288);
			AStudent.FindInfo(0518277);
			AStudent.PrintBase();
			ACollegeStudent.FindInfo(0518288);    //输出派生类的studName
			ACollegeStudent.FindInfo2(0518288);   //输出基类的studName
			ACollegeStudent.FindInfo3(0518288);   //调用基类的FindInfo方法
			ACollegeStudent.PrintBase();          //从派生类调用基类的方法
			ACollegeStudent.PrintDerived();       //从派生类调用派生类的方法
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -