收藏 分销(赏)

大学专业试卷《JAVA》试卷B.doc

上传人:二*** 文档编号:4574533 上传时间:2024-09-30 格式:DOC 页数:2 大小:60KB 下载积分:5 金币
下载 相关 举报
大学专业试卷《JAVA》试卷B.doc_第1页
第1页 / 共2页
本文档共2页,全文阅读请下载到手机保存,查看更方便
资源描述
院系:—————— 专业班级:——————— 姓名:——————— 学号:—————— 装 订 线 《JAVA语言编程》课程试卷B 适用专业: 考试日期: 闭卷 所需时间:120分钟 总分:100分 一、输出结果题:(共6小题,每小题5分,共30分) 1、public class Arrays { public static void main(String[] args) { int[] a1 = { 1, 2, 3, 4, 5 }; int[] a2; a2 = a1; for(int i = 0; i < a2.length; i++) a2[i]=a2[i]+i; for(int i = 0; i < a1.length; i++) System.out.println( "a1[" + i + "] = " + a1[i]); } } 2、public class ArrayCopyDemo { public static void main(String[] args) { char[] copyFrom = {'d','e','c','a','f','f','e','i','n','a'}; char[] copyTo = new char[7]; System.arraycopy(copyFrom, 2, copyTo, 0, 7); System.out.println(new String(copyTo)); } } 3、public class BankAccount { private int accountNumber; private float balance; public BankAccount(int number, float initBal){ accountNumber = number; balance = initBal;} public String toString(){ return("Account #" + accountNumber +" with balance " + new java.text.DecimalFormat("$0.00").format(balance));}} public class AccountTester { public static void main(String args[]) { BankAccount anAccount; anAccount = new BankAccount(100023,100); System.out.println(anAccount);} } 4、class A1{ int x = 20; public void setx(int i){ x = i;} void printa(){ System.out.println(x);} } class B1 extends A1{ int x=1; void printb() { super.x = super.x +10 ; System.out.println("super.x= " + super.x + " x= " + x);} } public class Exam4_4Test { public static void main(String[] args){ A1 a1 = new A1(); a1.setx(4); a1.printa(); B1 b1 = new B1(); b1.printb(); b1.printa(); b1.setx(6); b1.printb(); b1.printa();} } 5、abstract class Glyph { abstract void draw(); Glyph() { System.out.println("Glyph() before draw()"); draw(); System.out.println("Glyph() after draw()");} } class RoundGlyph extends Glyph { int radius = 1; RoundGlyph(int r) { radius = r; System.out.println("RoundGlyph(),radius="+ radius);} void draw() { System.out.println("draw(), radius = " + radius);}} public class PolyConstructors { public static void main(String[] args) {new RoundGlyph(5);} } 6、class Meal { Meal() { System.out.println("Meal()"); } } class Bread { Bread() { System.out.println("Bread()"); } } class Lunch extends Meal { Lunch() {System.out.println("Lunch()");} } class PortableLunch extends Lunch { PortableLunch() { System.out.println("PortableLunch()"); } } public class Sandwich extends PortableLunch { Bread b = new Bread(); Sandwich(){System.out.println("Sandwich()");} public static void main(String[] args) { new Sandwich(); } } 二、问答题:(共2小题,每小题5分,共10分) 1、抽象基类与接口的异同点? 2、试述哈希表存储对象的方式与数组、Vector及ArrayList不同? 三、编程题:(共4小题,每小题15分,共60分) 1、从屏幕上输入一个整数,然后输出它的翻转形式。 2、请自定义一个包Package1,包中含两个类,一个类用来计算正方形面积,另一个类用来计算长方形体积。在类test当中使用Package1包中的类计算一边长为10正方形面积,计算一长方形(10×20×30)的体积。 3、使用Vector存储四个字符串china、japan、english、american。然后将长度大于6的字符串从中移除。 4、设计一线程随机产生一整数放入一存储器中,存储器一次只能存放一个数。另一线程将打印出此整数。要求两线程要协同工作,先存后打印此数。共循环10次。
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 教育专区 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服