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

📄 9-1.cs

📁 java基础方面的一些实例代码
💻 CS
字号:
//程序9-1
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, int id)
		{
			department=deptmnt;
			studName=str;
			studID=id;
		}
		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 class Test
	{
		public static void Main()
		{
			Student AStudent = new Student("李四",0518277);
			CollegeStudent CollegeStudent=new CollegeStudent("计算机","张三", 0518288);
			AStudent.FindInfo(0518277);
			AStudent.PrintBase();
			CollegeStudent.FindInfo(0518288);
			CollegeStudent.PrintBase();
			CollegeStudent.PrintDerived();
		}
	}
}

⌨️ 快捷键说明

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