1、 JAVA考试试卷及答案 选择题 3、在Java Applet程序顾客自定义Applet子类中,一般需要重载父类( D )措施来完毕某些画 图操作。 A. start() B. stop() C. init() D. paint() 3、Java语言具有许多长处和特点,下列选项中,哪个反应了Java程序并行机制特点?B A)安全性 B)多线程 C)跨平台 D)可
2、移植 4、下列哪个类申明是对?D A)abstract final class HI{···} B)abstract private move(){···} C)protected private number; D)public abstract class Car{···} 6、在Java语言中,下列哪些语句有关内存回收阐明是对? B A.程序员必须创立一种线程来释放内存; B.内存回收程序负责释放无用内存 C.内存回收程序容许程序员直接释放内存 D.内存回收程序可以在指定时间释放内存对象 10、下列Object类中措施,哪一项不是完
3、全跟线程有关: A A.String toString() B.void notify() C.void notifyAll() D.void wait() 11、给出下面代码:C public class Person{ static int arr[] = new int[10]; public static void main(String a[]) { System.out.println(arr[1]); } } 下列说法中对是? A.编译时将产生错误; B.编译时对,运行时将产生错误;
4、 C. 输出零; D. 输出空。 12、字符串是Java已定义类型,有关它构造函数,下面说法不对是: B A.String(char[] value, int offset, int count) B.String(int[] codePoints,int offset, int count) C.String(String original) D.String(StringBuffer buffer) 13、下列说法中对是: C A.导入包会影响程序性能 B.包存储在类库中 C.包是类容器D.上述说法都不对 14、下列不是String类常用措施是:C A、bo
5、olean equals(String str) B、int compareTo(String str) C、int SetindexOf(String str) D、int lastIndexOf(String str) 17、体现式:(x>y) ? (z>w) ?x:z:w,(其中x=5,y=9,z=1,w=9)值为:D A、5 B、8 C、1 D、9 1、main措施是Java Application程序执行入口点,有关main措施措施头如下哪项是合法( B )? A、public st
6、atic void main( ) B、public static void main( String args[] ) C、public static int main(String [] arg ) D、public void main(String arg[] ) 5、欲构造ArrayList类一种实例,下列哪个措施是对 ? B A. ArrayList myList=new Object(); B. ArrayList myList=new ArrayList(); C. myList= new Object(); D. myList= n
7、ew ArrayList(); 7、哪个关键字可以对对象加互斥锁? B A.transient B.synchronized C.serialize D.static 9、下列论述中,错误是: D A、父类不能替代子类 B、子类可以替代父类 C、子类继承父类 D、父类包括子类 10、下列有关Java多线程并发控制机制论述中,错误是:BC A、Java中对共享数据操作并发控制是采用加锁技术 B、线程之间交互,倡导采用suspend()/resume()措施 C、共享数据访问权限都必须定义为private D、Java中没有提供检测与防止死锁专门机制,但应用
8、程序员可以采用某些方略防止死锁发生 12、下列哪一种措施不是applet程序构成部分:D A、init() B、start() C、stop() D、new() 15、Java应用程序中,程序执行总入口措施是:B A、start() B、main()C、run() D、init() 16、在Java实现线程有多少种措施:B A、1 B、2 C、3 D、4 18、下列Applet类措施中,在Applet整个生
9、命周期里至多只执行一次是:A A、init() B、start() C、stop() D、paint() 19、启动一种线程所调用措施是:C A、run() B、init() C、start() D、new() 判断题 1.一种Java类可以有多种父类。 4.Java小程序Applet主类父类必须是类Applet。 5.break语句可以用在循环和switch语句中。 6.在Java中,异常Exception是指程序在编译和运行进出现错误。 7.可以用new来创立一种类实
10、例,即对象。 8.Java使用16位Unicode字符集,而不仅仅为ASCII字符集,因此Java字符是一种16位无符号整 数。 10.子类组员变量能与其父类组员变量同名。 11.Java类中不能存在同名两个组员函数。 12.Java语言是编译性语言。 16.final措施不能被覆盖。 20.多数I/O措施在碰到错误是会抛出异常,因此在调用这些措施时必须对异常进行处理。 2.abstract 是抽象修饰符,可以用来修饰类及其属性和措施。 4.一种Java Applet源程序主类能有多种父类。 6.用javac编译Java源文献后得到代码叫字节码。 7.可以用类名调用实例措
11、施。 9.要想在类中实现多线程,类必须继承Thread类。 11.Java语言是平台无关语言。 12.在类静态措施中可以访问该类非静态数据组员。 13.Java中措施调用时参数传递都是按值传递,因此从措施退出时,参数值不会变化。 14.申明为final措施不能在子类中重载。 15.在子类中可以覆盖一种private措施。 19.在措施定义中,所有也许发生异常都必须用try{}catch(){}捕捉并处理 1.请写出输出成果 class change{ void changeint(int x){ x++; } public static void ma
12、in(String args[]){ int a=2; System.out.println("Before changed: "+"a="+a); //请系统输出Before changed: a= change cxz=new change(); cxz.changeint(a); System.out.println("After changed: "+"a="+a); } } 答案: Before changed: a= 2 After changed: a= 3 2. 下面程序
13、运行最终止果i是:___2_____ public class Foo { public static void main (String []args) { int i = 1; int j = i++; if ((i>++j) && (i++ ==j)) { i +=j; } } } 3、阅读如下程序,请写出输出成果 import java.lang.*; public class StrCompare { public static void main(S
14、tring[] args) { String str1 = "Hello, Java!", str2 = "hello, java!"; System.out.println(pareToIgnoreCase(str2)); System.out.println(str1.equals(str2)); System.out.println(str1.equalsIgnoreCase(str2)); } } 答: 0 False True 4、阅读如下程序,请写出输出第一行成果
15、 public class abc { public static void main(String args[ ]) { int i =3,j ; while (i>0){ j=3; while (j>0){ if (j<2) break; System.out.println( "j+and"+i); j--;
16、 } i--; } } } 答: j+and3 j+and3 j+and2 j+and2 j+and1 j+and1 5、 import java.io.*; public class abc { public static void main(String args[ ]) { AB s = new AB("Hello!","I love JAVA.");
17、 System.out.println(s.toString( )); } } class AB { String s1; String s2; AB( String str1 , String str2 ) { s1 = str1; s2 = str2; } public String toString( ) { return s1+s2;} } 答: Hello!I love JAVA. 6、阅读如下程序,请写出输出c.x=是多少 public class withstaticdata {
18、 static int x; int y; public static void main(String[] args) { withstaticdata a=new withstaticdata(); a.x=1; System.out.println(a.x);withstaticdata b=new withstaticdata(); b.x=2; System.out.println(b.x); System.out.println(a.x); withstaticdata c=new withstaticdata(); System.out.println(
19、 "c.x="+c.x); } } 答:2 public class StaticFun { static void incr(){ withstaticdata.x++ ; } public static void main( String [] args ) { StaticFun.incr(); } } 1、在横线上填上合适内容 import java.awt.*; import java.applet.*; public class AppletLife extends Applet //申明为Apple类
20、{ Color r; public AppletLife() //初始化 { System.out.println("Applet initing..."); r = Color.red; } public void start() { System.out.println("Applet starting..."); } public void stop() { System.out.println("Applet stopping..."); } public void paint(Graphics g) { System.out
21、println("Applet painting..."); g.setColor(r); g.drawString("Painting here!", 50, 60 ); } public void destroy() { System.out.println("Applet destroy..."); } } 2. 阅读如下程序,请写出输出成果 public class tt { public static void main(String[] args) { String s=new String("Bicycle"); int iBegin=1; int
22、iEnd=3; System.out.println(s.substring(iBegin,i End));} } 答:ic 3、请在对应划线上填上代码 public class CircumferenceTester { public static void main(String args[]) { Circle c1 = new Circle(); c1.radius = 50; Circle c2 = new Circle(); c2.radius = 10; double
23、circum1 = c1.circumference(); double circum2 = c2.circumference(); System.out.println( "Circle 1 has circumference " + circum1); System.out.println( "Circle 2 has circumference " + circum2); } } public class Circle { private static double PI = 3.141;
24、 //静态double 常量PI为 3.141 int radius; public double circumference() { return 2*PI*radius; } public double area() { return PI * radius * radius; } public void enlarge(int factor) { radius = radius * factor; } public boole
25、an fitsInside (Rectangle r) { return (2 * radius < r.width) && (2 * radius < r.height); } } 4、阅读如下程序,请写出输出成果 class father{ void speak(){ System.out.println( "I am father!"); } } public class son extends father{ void speak(){ super.speak(); System.out.println(
26、 "I am son!"); } public static void main(String args[]){ son cxz=new son(); cxz.speak(); }} 答: I am father! I am son! 5.写出下面程序运行成果 import java.io.*; class Parent { void printMe() { System.out.println("parent"); } } class Child extends Parent { void
27、 printMe() { System.out.println("child"); } void printAll() { super.printMe(); this.printMe(); printMe(); } } public class Class1 { public static void main(String args[ ]) { Child myC = new Child( ); myC.printAll( ); } } 答: parent ch
28、ild child 6.写出下面程序运行成果 import java.io.*; public class abc { public static void main(String args[]) { String s1 = "Hello!"; String s2 = new String("World!"); System.out.println(s1.concat(s2)); } }
29、答: Hello!World! 定义能计算圆面积、周长类circle,半径r为私有数据分量,其值由类circle构造函数初始化,类 circle提供读取半径r措施getr();计算面积措施area();计算周长措施circlelength()。 再定义类circlecomputer其包括程序运行所需措施main,圆半径为1,请设计程序, 必须使用 类circle构造函数及措施初始化数据分量和计算圆面积、周长并打印出如下形式成果。 半径 面积 周长 答:public class circle { private int r; private static doubl
30、e PI = 3.141; public circle(int r) { this.r = r; } public int getR() { return r; } public double area() { return PI * r * r; } public double circlelength() { return 2 * PI * r; } } public class circlecomputer { public static void main(String[] args) { circle c = new circle(1);// 实例
31、化 circle 并设置半径为 1 System.out.println(" 半径 面积 周长 "); System.out.print(c.getR()); System.out.print(" "); System.out.print(c.area());System.out.print(" "); System.out.print(c.circlelength()); } }定义能 计算三角形面积、周长类js,三边a,b,c都为私有数据分量,其值由类sj构造函数初始 化,类js提供读取各边长度a,b,c措施分别为geta(); getb(); getc
32、); 计算面积措施area(); 计算周长措施sjlength()。 (三角形面积公式:c) -b)(s-a)(s-s(s 其中s=(a+b+c)/2) 再定义类jxcomputer其包括程序运行所需措施main,矩三角形三边a为3,b为6,c为8请设计程 序必须使用类sj构造函数及措施初始化数据分量和计算三角形面积、周长并打印出如下形式结 果。 a b c 面积 周长 答:public class js { private int a; private int b; private int c; public js(int a, int b, in
33、t c) { this.a = a; this.b = b; this.c = c; } public int getA() { return a; } public int getB() { return b; } public int getC() { return c; } public double area() { double s = this.s();return Math.sqrt(s * (s - a) * (s - b) * (s - c)); } public double sjlength() { return a + b + c;
34、 } public double s() { return this.sjlength() / 2; } } import java.text.DecimalFormat; public class jxcomputer { public static void main(String[] arg) { js j = new js(3, 6, 8); System.out.println("a b c 面积 周长 "); System.out.print(j.getA()); System.out.print(" "); System.out.print(j.getB()); System.out.print(" "); System.out.print(j.getB()); System.out.print(" "); DecimalFormat df = new DecimalFormat("#.00"); // 保留两位小数,此句可以不用 System.out.print(df.format(j.area())); System.out.print(" "); System.out.print(j.sjlength()); }






