《Java实验测试题试卷.docx》由会员分享,可在线阅读,更多相关《Java实验测试题试卷.docx(4页珍藏版)》请在第一文库网上搜索。
1、实验测试题1.实例成员和类成员实验的模板代码TeSt2015.javac1assA【代码1】声明一个实例f1oat变量a代码2声明一个static的f1oat变量bvoidsetA(f1oata)(【代码3】/将参数a的值赋值给成员变量avoidsetB(f1oatb)【代码4)/将参数b的值赋值给成员变量b)f1oatgetA()returna;If1oatgetB()returnb;)voidinputA()System.out.print1n(a);)staticvoidinutB()System.out.print1n(b);)pub1icc1assTeSt2015pub1icstat
2、icvoidmain(Stringargs)【代码5】/通过类名操作类变量b,并赋值100代码6/通过类名调用方法inputB()Acat=newA();Adog=newA();【代码7】Zcat调用方法setA(inta)将cat的成员a的值设置为200【代码8】/ca1调用方法setB(intb)将cat的成员b的值设置为400代码9/dog调用方法setA(inta)将dog的成员a的值设置为200代码10/dog调用方法setB(intb)将dog的成员b的值设置为900【代码11Cat调用inputA()代码12/cat调用inputB()代码13/dog调用inputA()代码14
3、/dog调用inpu(B()2.继承实验的模板代码Test2015_2.javac1assPeop1eprotecteddoub1eweight,height;pub1icvoidspeakHe11o()System-Out-Print1nCyayawawa);)pub1icvoidaverageHeight()height=173;System.out.print1n(averageheight:+height);)pub1icvoidaverageWeight()weight=70;System.out.print1n(averageweight:,r+weight);I)c1assChi
4、naPeop1eextendsPeop1e【代码1】/重写PUb1iCVOidSPeakHe11o()方法,要求输出类似“你好,吃饭了吗”/这样的汉语信息【代码2】/重写PUb1iCVOidaVerageHeight()方法,要求输出类似/“中国人的平均身高:168.78厘米”这样的汉语信息代码3/重写pub1icvoidaverageWeight()方法,要求输出类似/“中国人的平均体重:65公斤”这样的汉语信息pub1icvoidChinaGongfu()【代码4】/输出中国武术的信息,如“坐如钟,站如松,睡如弓”等)c1assAmericanPeopIeextendsPeop1e【代码5
5、】重写pub1icvoidSPeakHe1k)()方法,要求输出类似“Howdoyoudo”这样的英语信息代码6重写pub1icvoidaverageHeight()方法代码7重写pub1icvoidaverageWeight()方法pub1icvoidamericanBoxing()【代码8】/输出拳击的信息,如“直拳”、“钩拳”等c1assBeijingPeop1eextendsChinaPeop1e【代码9】/重写pub1icvoidspeakHe11o()方法,要求输出类似“您好!北京欢迎您!”这样的汉语信息代码10/重写pub1icvoidaverageHeight()方法代码11/
6、重写pub1icvoidaverageWeight()方法pub1icvoidbeijingpera()【代码12】J/输出京剧的信息,如京剧是国粹,剧中有老生,小生,花旦等。pub1icc1assTest2015_2pub1icstaticvoidmain(S1ringargs)ChinaPeop1echinaPeop1e=newChinaPeop1e();AmericanPeop1eamericanPeop1e=newAmericanPeop1e();BeijingPeop1ebeijingPeop1e=newBeijingPeop1e();chinaPeop1e.speakHeI1o()
7、;americanPeop1e.speakHe11o();beijingPeop1e.speakHe11o();chinaPeop1e.averageHeigh1();americanPeop1e.averageHeight();beijingPeop!e.averageHeight();chinaPeop1e.averageWeight();americanPeop1e.averageWeight();beijingPeop1e.averageWeight();chinaPeop1e.chinaGongfu();americanPeop1e.americanBoxing();beijingP
8、eopIe.beijingOpera();beijingPeop1e.chinaGongfu();3.异常实验的模板代码ExceptionExamp1eJava【代码1】类声明,声明一个EXCePIiOn的子类No1OWer1e1Ier(pub1icvoidprint()System.out.printf(,):【代码2】类声明,声明一个EXCePIion的子类NoDigi1pub1icvoidprint()System.out.printf(%c/*);c1assPeop1evoidprint1etier(charc)throwsNo1ower1etierif(c,z)NO1OWer1ett
9、ernO1oWer1etter=【代码3/创建No1OWer1etter类型对象【代码4】/抛出no1ower1ettere1seSys(em.ou(.print(c);voidprintDigit(charc)throwsNoDigitif(c91)NoDigitnoDigi(=【代码5/创建NoDigi1()类型对象【代码6】/抛出noDigit)e1seSystem.out.print(c);)pub1icc1assExceptionExamp1epub1icstaticvoidmain(Stringargs)Peop1epeop1e=newPeop1e();fr(inti=0;i128;i+)Iry(peop1e.print1etter(char)i);代码7/处理No1ower1etter(e.print();)fbr(inti=0;i128;i+)try(peop1e.printDigit(char)i);【代码8】/处理NoDigit(e.print();