实验一 继承与多态编程练习

实验一 继承与多态编程练习

ID:38675229

大小:106.81 KB

页数:5页

时间:2019-06-17

实验一 继承与多态编程练习_第1页
实验一 继承与多态编程练习_第2页
实验一 继承与多态编程练习_第3页
实验一 继承与多态编程练习_第4页
实验一 继承与多态编程练习_第5页
资源描述:

《实验一 继承与多态编程练习》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、实验报告姓名:孟凡响学号:115767日期:2014-01-02实验名称:实验一继承与多态编程练习成绩:一、实验目的及要求实验目的1.理解面向对象思想,体会面向对象思想在编程中的应用。2.掌握VisualC#.NET类的创建(成员,方法,属性),类的继承,类的多态性及类的方法的重载。3.理解继承的含义,掌握派生类的定义方法和实现;4.编写体现类的继承性(成员变量,成员方法,成员变量隐藏)的程序;5.编写体现类多态性(成员方法重载,构造方法重载)的程序。实验要求1.写出程序,并调试程序,要给出测试数据和实验结果。2.整理上机步骤,总结经验和

2、体会。3.完成实验日志和上交程序。二、实验环境WindowsXP操作系统,Visualstudio.net2005三、实验源程序及关键代码解释Using指令集:usingSystem;usingSystem.Collections.Generic;usingSystem.Text;定义Employee类publicclassEmployee{protectedstringname;privatestringsexy;privateintsalary;privatestringdate;privatestringdepartment;pri

3、vatestringtelnum;publicEmployee(){}publicEmployee(string[]args){name=args[0];sexy=args[1];salary=Convert.ToInt32(args[2]);date=args[3];department=args[4];telnum=args[5];}//virtual关键字,方法可以重写publicvirtualvoidDisplay(){Console.WriteLine("Name:{0}",name);Console.WriteLine("Se

4、xy:{0}",sexy);Console.WriteLine("Salary:{0}",salary);Console.WriteLine("Date:{0}",date);Console.WriteLine("Department:{0}",department);Console.WriteLine("Telephone:{0}",telnum);}}定义Employer类,继承基类EmployeepublicclassEmployer:Employee{privatestringposition;privatestringpromo

5、te_date;privatestringnumber;privatestring[]Ename=newstring[50];publicEmployer(string[]args):base(args){position=args[6];promote_date=args[7];number=args[8];for(inti=0;i

6、play();Console.WriteLine("Position:{0}",position);Console.WriteLine("Promote_date:{0}",promote_date);Console.WriteLine("Numberofemployee:{0}",number);for(inti=0;i

7、er的构造函数和方法并显示:publicclassClass1{staticvoidMain(string[]args){Console.WriteLine("----------------软件051------孔令民------051023----------------------");string[]employee1=newstring[50];Console.WriteLine("Pleaseinputimformationofemployee:");Console.WriteLine("(name,sexy,salary,d

8、ate,department,telephonenumber)");employee1=Console.ReadLine().Split('');//调用Employee构造函数Employe

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。