java练习题

 

复习 题
一、 单选题(40道)
1. 电子商务有许多分类,其中 B to C 是指( )。
A、企业与企业 B、企业与消费者 C、消费者与消费者 D、企业与政府
2. 在一个由客户端,协议防火墙、中间层(DMZ)、域防火墙及企业内部网构成的电子商务系统中,
一般情况下,协议防火墙会允许哪个/些协议通过?
A. IIOP B. FTP C. HTTP/HTTPS D. JAVA
3. 在HTML文件中可以嵌入JSP表达式。下面哪一个表明了正确的嵌入方式?
A. <! 表达式内容 >
B. <%= 表达式内容 %>
C. <JSP:表达式内容>
D. <@ 表达式内容 @>
4. 下面哪一个关于IBM电子商务应用框架的阐述是正确的?
A. 它是一种开放的、不安全的体系结构,
B. 系统的当机时间不会影响雇员的生产率
C. 该框架中的后台数据库只支持DB2
D. 它是基于工业标准的,能够提供好的灵活性和可扩展性
5. 下面哪些是短整型short的取值范围:
A.-27 ——27-1
B.0 ——215
C.–215 —— 215-1
D.–231 ——231-1
6. 下列那个是char类型的值的范围?
A. -27~27-1
B. 0~216-1
C. 0~216
D. 0~28
7. 关于java的面向对象的编程特性中的封装机制,以下说法正确的是?
A. 将问题的特征属性与问题的功能方法相组合在一起形成一个类。
B. 将问题的特征属性与问题的功能方法相分离,形成各自的程序。
C. 将问题的特征属性内嵌到问题的功能方法的定义体中。
D. 对具体问题只需给出其功能实现方法,而不必给出其特征属性的定义。
- 1 -
8. MyClass类定义如下:
class MyClass{
public MyClass(int x){
}
}
如下方式创建对象,哪些是正确的 ?
A. MyClass myobj=new MyClass;
B. MyClass myobj=new MyClass( );
C. Myclass myobj= new MyClass(1);
D. MyClass myobj=new MyClass(1,2);
9. 下列各种java中的方法的定义,那种是正确的?
A. void myFun(int X=1){ }
B. void myFun(int & X){ }
C. void myFun(int X ){ }
D. void myFun(int * X){ }
10. 设Derived类为Base类的子类,则如下对象的创建语句中那些是错误的?
A. Base Obj=new Derived();
B. Derived Obj=new Base();
C. Base Obj=new Base();
D. Derived Obj=new Derived();
11. 运行下列程序, 会产生什么结果
public class X extends Thread implements Runable{
public void run(){
System.out.println("this is run()");
}
public static void main(String args[])
{
Thread t=new Thread(new X());
t.start();
}
}
A 第一行会产生编译错误
B 第六行会产生编译错误
C 第六行会产生运行错误
D 程序会运行和启动
12. 给定下列代码:
1 class Parent { - 2 -
2 private String name;
3 public Parent(){}
4 }
5 public class Child extends Parent {
6 private String department;
7 public Child() {}
8 public String getValue(){return name;}
9 public static void main(String arg[]){
10 Parent p = new Parent();
11 }
12 }
上述代码的那些行将会导致错误?
A. line 3
B. line 6
C. line 7
D. line 8
E. line 10
13. 给出下面代码:
public class Person{
static int arr[] = new int[10];
public static void main(String a[])
{
System.out.println(arr[1]);
}
}
那个语句是正确的?
A 编译时将产生错误;
B 编译时正确,运行时将产生错误;
C 输出零;
D 输出空。
14. MAX_LENGTH是int型public成员变量, 变量值保持为常量100,
用简短语句定义这个变量。
A public int MAX_LENGTH=100;
B final int MAX_LENGTH=100;
C final public int MAX_LENGTH=100;
D public final int MAX_LENGTH=100. - 3 -
15. 类Teacher和Student是类Person的子类;
Person p;
Teacher t;
Student s;
//p, t and s are all non-null.
if(t instanceof Person) { s = (Student)t; }
最后一句语句的结果是:
A 将构造一个Student对象;
B 表达式是合法的;
C 表达式是错误的;
D 编译时正确,但运行时错误。
16. 哪个关键字可以抛出异常?
A transient
B finally
C throw
D static
17. Main()方法的返回类型是:
A int
B void
C boolean
D static
18. 哪个关键字可以对对象加互斥锁?
A transient
B synchronized
C serialize
D static
19. 下列哪些语句关于内存回收的说明是正确的?
A 程序员必须创建一个线程来释放内存;
B 内存回收程序负责释放无用内存
C 内存回收程序允许程序员直接释放内存
D 内存回收程序可以在指定的时间释放内存对象
20. 欲构造ArrayList类的一个实例,此类继承了List接口,
下列哪个方法是正确的?
A ArrayList myList=new Object();
B List myList=new ArrayList();
C ArrayList myList=new List();
- 4 -
D List myList=new List();
21. paint()方法使用哪种类型的参数?
A Graphics
B Graphics2D
C String
D Color
22. 指出正确的表达式
A byte=128;
B Boolean=null;
C long l=0xfffL;
D double=0.9239d;
23. 要从文件" file.dat"文件中读出第10个字节到变量C中,下列哪个方法适合?
A FileInputStream in=new FileInputStream("file.dat"); in.skip(9); int c=in.read();
B FileInputStream in=new FileInputStream("file.dat"); in.skip(10); int c=in.read();
C FileInputStream in=new FileInputStream("file.dat"); int c=in.read();
D RandomAccessFile in=new RandomAccessFile("file.dat"); in.skip(9); int c=in.readByte();
24. 容器被重新设置大小后,哪种布局管理器的容器中的组件大小不随容器大小的变化而改变?
A CardLayout
B FlowLayout
C BorderLayout
D GridLayout
25. 下列哪些不属于软件维护阶段?
A. 诊断和改正在使用过程中发现的软件错误
B. 诊断和改正在开发过程中发现的软件错误
C. 根据用户需求进行软件升级
D. 修改软件为将来的维护活动预先做准备
26. 下列那种java组件为容器组件
A. List列表框
B. Choice下拉式列表框
C. Panel面板
D. MenuItem 命令式菜单项
27. 如下那种Java的控件将不会引发动作事件(ActionEvent)?
A. Button
B. MenuItem
- 5 -
C. Panel
D. CheckboxMenuItem
28. 编译java Applet源程序文件将产生相应的结果文件,这些结果文件的扩展名是什么?
A. .java
B. .class
C. .html
D. .exe
29. 现在有两个类:Person与Chinese,Chinese试图继承Person类,如下项目中哪个是正确的写法?
A. class Chinese extents Person{}
B. class Chinese extants Person{}
C. class Chinese extends Person{}
D. class Chinese extands Person{}
30. JPanel组件的默认布局管理器是哪一项?
A. GridLayout
B. CardLayout
C. BorderLayout
D. FlowLayour
31. 下列哪一项不属于面向对象程序设计的基本要素?
A. 类
B. 对象
C. 方法
D. 安全
32. 下面程序的输出结果是。
public class ex2 {
public static void main(String[] args)
{
for(int cnt=0;cnt<10;cnt++)
{
if(cnt==5)
break;
System.out.print(cnt);
}
}
}
A. 0 1 2 3 4
B. 6 7 8 9
C. 0 1 2 3 4 6 7 8 9
D. 5
- 6 -
33. 给定下面的代码片段:
1) String str = null;
2) if ((str != null) && (str.length() > 10)) {
3) System.out.println("more than 10");
4) }
5) else if ((str != null) & (str.length() < 5)) {
6) System.out.println("less than 5");
7) }
8) else { System.out.println("end"); }
哪些行会导致错误?
A line 1
B line 2
C line 5
D line 8
34. 下面哪种注释方法能够支持javadoc命令:
A /**...**/
B /*...*/
C //
D /**...*/
35. 欲编写如下图的一个界面,用于显示用户指定的图像: 如果在区域A中只能放置一个AWT组件,从各组件的本来功能角度考虑,最好使用哪种组件:
A TextArea
B Panel
C Applet
D Canvas
36. 界面如上题所示。若"Button1"的功能是:点击后弹出一个用于输入的界面,获取用户想要显示的图像文件名,则该界面最好是(从编程简单和程序不易出错的角度考虑):
A 模式(Modal)Dialog
B 非模式(None-modal)Dialog
C FileDialog
D Frame
37. 界面如上题所示。如果在A区域使用某种AWT组件(java.awt.Component的子类)来负责绘制图像,则绘图的语句最好应放在该组件的哪个方法中(考虑到应用程序和Java虚拟机的AWT线程都会要求重画该组件)?
A 构造方法
B paint(Graphics g)
C update(Graphics g)
D repaint()
- 7 -
38. 下面关于Applet的说法正确的是
A Applet也需要main方法
B Applet必须继承自java.awt.Applet
C Applet能访问本地文件
D Applet程序不需要编译
39. 下列代码执行的结果是?
public class text {
public static void main(String[] args) {
int x= 1, y = 6;
while (y--==6) {x--;}
System.out.println("x=" + x +" ,y =" + y);
}
}
A. 程序能运行,输出结果:x=0,y=5
B.程序能运行,输出结果:x=-1,y=4
C.程序能运行,输出结果:x=0,y=4
D. 程序不能编译
40. 下列代码哪几行会出错:
1) public void modify() {
2) int I, j, k;
3) I = 100;
4) while ( I > 0 ) {
5) j = I * 2;
6) System.out.println (" The value of j is " + j );
7) k = k + 1;
8) I--;
9) }
10) }
A line 4
B line 6
C line 7
D line 8
二、 多选题(40道)
1. 下面哪些是合法的标识符:
A. $persons
B.TwoUsers
C. *point - 8 -
D. this
E. _endline
2. 下面关于使用"<<"和 ">>"操作符的哪些结果是对的?
A. 1010 0000 0000 0000 0000 0000 0000 0000 >> 4 的结果是
0000 1010 0000 0000 0000 0000 0000 0000
B. 1010 0000 0000 0000 0000 0000 0000 0000 >> 4 的结果是
1111 1010 0000 0000 0000 0000 0000 0000
C. 1010 0000 0000 0000 0000 0000 0000 0000 >>> 4的结果是
0000 1010 0000 0000 0000 0000 0000 0000
D. 1010 0000 0000 0000 0000 0000 0000 0000 >>> 4的结果是
1111 1010 0000 0000 0000 0000 0000 0000
3. 执行下列代码后,哪个结论是正确的 String[] s=new String[10];
A s[10] 为 "";
B s[9] 为 null;
C s[0] 为未定义
D s.length 为10
4. 下面哪些不是java的基本数据类型?
A. short
B. Boolean
C. Int
D. float
5. 下面有关java代码安全性的叙述哪些是对的。
A. 字节码校验器加载查询执行需要的所有类。
B. 运行时解释器执行代码。
C. 在运行时,字节码被加载,验证然后在解释器里面运行。
D. 类加载器通过分离本机文件系统的类和从网络导入的类增加安全性。
6. "result"是一个boolean型的变量,下面的哪些表达式是合法的?
A. result = true;
B. if ( result ) { // do something... }
C. if ( result!= 0 ) { // so something... }
D. result = 1
7. 下面的表达式哪个是正确的?
A String s="你好";int i=3; s+=i;
B String s="你好";int i=3; if(i==s){ s+=i};
C String s="你好";int i=3; s=i+s;
D String s="你好";int i=3; s=i+; - 9 -
E. String s=null; int i=(s!=null)&&(s.length>0)?s.length():0;
8. 选出合理的标识符
A _sys1_lll
B 2mail
C $change
D class
9. 哪个布局管理器使用的是组件的最佳尺寸( preferred size)
A FlowLayout
B BorderLayout
C GridLayout
D CardLayout
E.GridBagLayout
10. 下列哪个方法可用于创建一个可运行的类?
A public class X implements Runable{ public void run(){ ......} }
B public class X implements Thread{ public void run(){ ......} }
C public class X implements Thread{ public int run(){ ......} }
D public class X implements Runable{ protected void run(){ ......} }
E.public class X implements Thread{ public void run(){ ......} }
11. 下面哪个方法可以在任何时候被任何线程调用?
A notify()
B wait()
C notifyAll()
D sleep()
E.yield()
F.synchronized(this)
12. 给出下列代码:
switch(x){
case 1:System.out.println(“Test 1”);break;
case 2:
case 3:System.out.println(“Test 2”);break;
default:System.out.println(“end”); }
x为什么值时,会输出Test 2 ?
A. 0
B. 1
C. 2
D. 3
- 10 -
13. 下面关于变量及其范围的陈述哪些是对的?
A. 实例变量是类的成员变量。
B. 实例变量用关键字static声明。
C. 在方法中定义的局部变量在该方法被执行时创建
D. 局部变量在使用前必须被初始化。
14. 下面关于继承的哪些叙述是正确的?
A. 在java中只允许单一继承。
B. 在java中一个类只能实现一个接口。
C. 在java中一个类不能同时继承一个类和实现一个接口。
D. java的单一继承使代码更可靠。
15. 给定下列代码:
public class Parent {
public int addValue( int a, int b) {
int s;
s = a+b;
return s;
}
}
class Child extends Parent {
}
下列哪些方法可以作为Child类的方法?
A. int addValue( int a, int b ){// do something...}
B. public void addValue (){// do something...}
C. public int addValue( int a ){// do something...}
D. public int addValue( int a, int b )throws MyException {//do something...}
16. 下面的哪些程序片断可能导致错误?
A. String s = "Gone with the wind";
String t = " good ";
String k = s + t;
B. String s = "Gone with the wind";
String t;
t = s[3] + "one";
C. String s = "Gone with the wind";
String standard = s.toUpperCase();
D. String s = "home directory";
String t = s - "directory";
17. 下列哪些接口在Java中没有定义相对应的Adapter类?
A. MouseListener
B. KeyListener
C. ActionListener
- 11 -
D. ItemListener
E. WindowListener
18. 如果下列的方法能够正常运行,在控制台上将显示什么?
public void example(){
try{
unsafe();
System.out.println("Test1");
}
catch(SafeException e)
{System.out.println("Test 2");}
finally{System.out.println("Test 3");}
System.out.println("Test 4");
}
A Test 1
B Test 2
C Test 3
D Test 4
19. 下列哪些情况可以终止当前线程的运行?
A 抛出一个例外时。
B 当该线程调用sleep()方法时。
C 当创建一个新线程时。
D 当一个优先级高的线程进入就绪状态时。
20. 下列那些项目不是java的主要优点。
A. 直接操作内存,功能强大
B. 一次编写,到处运行
C. 纯面向对象的语言
D. 可以通过拖拽的方式快速开发程序界面
21. 下面有几个定义的标识符,找出合乎java规范的标识符。
A. IDoLoveThisGame
B. const
C. 3Person
D. _People5
22. public class MyClass{
public static void main(String args[]) {}
_____class MyInnerClass {}
}
在以上Java代码中的横线上,可放置哪些修饰符。
A. public - 12 -
B. private
C. static
D. friend
23. 在java语言中,下列表达式返回true的是哪些项目。
A. "john"=="john"
B. "john".equals("john")
C. "john"="john"
D. "john".equals(new Button("john"))
24. 以下Java代码编译运行后,下列选项中,()会出现在输出结果中。
public class text3{
public static void main(String args[]) {
for(int i=0;i<3;i++) {
for(int j=3;j>=0;j--) {
if(i == j)
continue;
System.out.println(“i=”+i+“j=”+j);
}
}
}
}
A. i=0 j=3
B. i=0 j=0
C. i=2 j=2
D. i=0 j=2
E. i=0 j=1
25. 运行下列Java代码后,下面选项中,包含在输出结果中的是()。
public class Example{
public static void main(String args[]){
int i=0;
do{
System.out.println(〞Doing it for i is 〞+i);
}while(--i>0);
System.out.println(〞Finished〞);
}
}
A Doing it for i is 3
B Doing it for i is 1
C Doing it for i is 2
D Doing it for i is 0
E Finished
- 13 -
26. public class parent {
int change() {}
}
class Child extends Parent { }
哪些方法可加入类Child中?
A public int change(){}
B int chang(int i){}
C private int change(){}
D abstract int chang(){}
27. String s = "hello";
String t = "hello";
char c[] = {'h','e','l','l','o'} ;
下列哪些表达式返回true?
A s.equals(t);
B t.equals(c);
C s==t;
D t.equals(new String("hello"));
28. 给出下面代码段:
1) switch(m)
2) { case 0: System.out.println("case 0");
3) case 1: System.out.println("case 1"); break;
4) case 2:
5) default: System.out.println("default");
6) }
下列m的哪些值将引起"default"的输出?
A 0
B 1
C 2
D 3
29. 下列哪些说法是正确的?
A Java 语言只允许单一继承
B Java 语言只允许实现一个接口
C Java 语言不允许同时继承一个类并实现一个接口
D Java 语言的单一继承使得代码更加可靠
30. 下列关于"<<"和">>"的运算,哪些是正确的?
A 0000 0100 0000 0000 0000 0000 0000 0000<<5 的运行结果是 1000 0000 0000 0000 0000 0000 0000 0000
B 0000 0100 0000 0000 0000 0000 0000 0000<<5的运行结果是 1111 1100 0000 0000 0000 0000 0000 0000
C 1100 0000 0000 0000 0000 0000 0000 0000>>5的运行结果是 1111 1110 0000 0000 0000
- 14 -
0000 0000 0000
D 1100 0000 0000 0000 0000 0000 0000 0000>>5的运行结果是 0000 0110 0000 0000 0000 0000 0000 0000
31. 下述哪些说法是正确的?
A 实例变量是类的成员变量
B 实例变量是用static关键字声明的
C 方法变量在方法执行时创建
D 方法变量在使用之前必须初始化
32. 对于下列代码:
public class Sample{
long length;
public Sample(long l){ length = l; }
public static void main(String arg[]){
Sample s1, s2, s3;
s1 = new Sample(21L);
s2 = new Sample(21L);
s3 = s2;
long m = 21L;
}
}
下列哪些表达式返回值为'true'?
A s1 = = s2;
B s2 = = s3;
C m = = s1;
D s1.equals(m)
33. 构造BufferedInputStream的合适参数是哪个?
A BufferedInputStream
B BufferedOutputStream
C FileInputStream
D FileOuterStream
E. File
34. 下列说法正确的是
A java.lang.Clonable是类
B java.lang.Runnable是接口
C Double对象在java.lang包中
D Double a=1.0是正确的java语句
35. 指出正确的表达式
A double a=1.0; - 15 -
B Double a=new Double(1.0);
C byte a = 340;
D Byte a = 120;
36. 定义一个类名为"MyClass.java"的类,并且该类可被一个工程中的所有类访问,那么该类的正确声明应为:
A private class MyClass extends Object
B class MyClass extends Object
C public class MyClass
D public class MyClass extends Object
37. 指出下列哪个方法与方法public void add(int a){}为合理的重载方法。
A public int add(int a)
B public void add(long a)
C public void add(int a,int b)
D public void add(float a)
38. 在Java代码中,public static void main方法的参数描述正确的是()。
A) String args[]
B) String[] args
C) Strings args[]
D) String args
39. 选择错误的标识符。
A. IDoLikeTheLongNameClass
B. $byte
C. const
D. 3_case
40. Applet默认使用下列哪一个布局管理器?
A. BorderLayout
B. FlowLayout
C. BoxLayout
D. GridLayout
三、 程序解析题(10道)
1. 下面哪一项编译不会有错?
A. package testpackage;
public class Test{//do something…}
class MyClass{}
B.import java.io.*;
package testpackage; - 16 -
public class Test{//do something…}
C.import java.io.*;
class Person{//do something…}
public class Test{//do something…}
D. import java.io.*;
import java.awt.*;
public class Test{//do something…}
2. 给出下面代码:
1) class Parent {
2) private String name;
3) public Parent(){}
4) }
5) public class Child extends Parent {
6) private String department;
7) public Child() {}
8) public String getValue(){ return name; }
9) public static void main(String arg[]) {
10) Parent p = new Parent();
11) }
12) }
那些行将引起错误?
A 第3行
B 第6行
C 第7行
D 第8行
3. 编译下列代码的结果是?
public class SiteInfo{ String webSite="http://www.lanw.com"+'/'+"default.htm"; public String getSite(){ return webSite; } }
A. 没有任何问题
B. 编译器会报错误:':' expected for the statement in line 2.
C. 缺少main方法.
D. getSite()方法中的return webSite有问题
4. 给出下面代码段
1) public class Test {
2) int m, n;
3) public Test() {}
4) public Test(int a) { m=a; } - 17 -
5) public static void main(String arg[]) {
6) Test t1,t2;
7) int j,k;
8) j=0; k=0;
9) t1=new Test();
10) t2=new Test(j,k);
11) }
12) }
哪行将引起一个编译时错误?
A line 3
B line 5
C line 6
D line 10
5. 对于下列代码:
1) class Person {
2) public void printValue(int i, int j) {//... }
3) public void printValue(int i){//... }
4) }
5) public class Teacher extends Person {
6) public void printValue() {//... }
7) public void printValue(int i) {//...}
8) public static void main(String args[]){
9) Person t = new Teacher();
10) t.printValue(10);
11) }
第10行语句将调用哪行语句??
A line 2
B line 3
C line 6
D line 7
6. 给定下面的Java程序段:
1) StringBuffer sb = new StringBuffer("abc");
2) String s = new String("abc");
3) sb.append("def");
4) s.append("def");
5) sb.insert(1, "zzz");
6) s.concat(sb);
7) s.trim();
下面那些描述是正确的:
A. 编译器在 line 1产生错误.
- 18 -
B. 编译器在 line 2产生错误.
C. 编译器在 line 3产生错误.
D. 编译器在 line 4产生错误.
E. 编译器在 line 5产生错误.
F. 编译器在 line 6产生错误.
G. 编译器在 line 7产生错误.
7. 给定如下的代码:
1) public class Test { 2) int m, n; 3) public Test() {} 4) public Test(int a) { m=a; } 5) public static void main(String arg[]) { 6) Test t1,t2; 7) int j,k; 8) j=0; k=0; 9) t1=new Test();
10) t2=new Test(j,k); 11) } 12) } 下列哪一行会在编译时产生错误? A. line 3 B. line 5 C. line 6 D. line 10
8. 给定如下的代码:
public class Person{ int arr[] = new int[10]; public static void main(String a[]) { System.out.println(arr[1]); } }
A. 编译时出错。B. 编译时正确而运行时出错。C. 输出0。D. 输出null。
9. 下面哪些代码段是正确的Java源程序?
A. package testpackage;
public class Test{//do something...}
B. import java.io.*;
- 19 -
package testpackage;
public class Test{// do something...}
C. import java.io.*;
class Person{// do something...}
public class Test{// do something...}
D. import java.io.*;
import java.awt.*;
public class Test{// do something...}
10. 给出下面代码:
public class test{
static int a[] = new a[10];
public static void main(String args[]) {
System.out.println(arr[10]);
}
}
那个选项是正确的?
A 编译时将产生错误;
B 编译时正确,运行时将产生错误;
C 输出零;
D 输出空。
四、 程序填空题(10道)
1. 写出下列代码执行的结果:
public class Test1 {
public static void main(String[] args) {
for (int i=-2; i<2; i++) {
if (i==0) continue;
System.out.println("i=" + i);
}
}
}
答案:
i=-2
i=-1
i=1
2. 给定如下代码,程序输出的结果是:
public class Test {
void printValue(int m){
do { System.out.println("The_value_is_"+m);
}
- 20 -
while( --m > 10 )
}
public static void main(String arg[]) {
int i=10;
Test t= new Test();
t.printValue(i);
}
}
答案:
The_value_is_10
3. 写出下列程序的结果
public class Test{
public static void main(String args[]){
String s1=”Henry Lee”;
String s2=”Java Applet”;
String s3=”Java”;
String st;
if(s.compareTo(s2)<0)
st=s2;
else
st=s1;
if(st.compareTo(s3)<0)
st=s3;
System.out.println(“big=”+st);
}
}
答案:
Java Applet
4. 写出下面程序运行的结果:
import java.util.Arrays;
public class SortArray {
public static void main(String args[]) {
String[] str = {"size", "abs","length","class"};
Arrays.sort(str);
for (int i=0; i<str.length; i++)
System.out.print(str[i]+"_");
}
}
答案:
abs_class_length_size
5. 定义A,B如下:
class A
{
- 21 -
int a=1;
double d=2.0;
void show( )
{
System.out.println("Class A:a="+a +" d="+d);
}
}
class B extends A
{
float a=3.0f;
String d="Java program.";
void show( )
{
super.show( );
System.out.println("Class B:a="+a +" d="+d);
}
}
(1) 若在应用程序的main方法中有以下语句:
A a=new A();
a.show();
则输出的结果如何?
(2) 若在应用程序的main方法中定义类B的对象b:
A b=new B();
b.show();
则输出的结果如何?
答案:
(1)Class A:a=1 d=2.0
(2)Class A:a=1 d=2.0
Class B:a=3.0 d=Java program.
6. 以下程序段的输出结果为 。
int j=2;
switch ( j ) {
case 2:
System.out.print(“Value is two.”);
case 2+1 :
System.out.println(“Value is three.”);
break;
default:
System.out.println(“value is “+j);
break;
}
答案:
Value is two.Value is three
7. 阅读以下程序段:
class Parent
{
void printMe()
- 22 -
{
System.out.println(“parent”);
}
}
class Child extends Parent
{
void printMe()
{
System.out.println(“child”);
}
void printAll()
{
super.printMe();
this.printMe();
printMe();
}
}
public class Test_this
{
public static void main(String args[ ])
{
Child myC=new Child();
myC.printAll();
}
}
输出结果为:
答案:
parent
child
child
8. 以下程序段的输出结果为 。
public class EqualsMethod {
public static void main(String[] args) {
Integer n1 = new Integer(47);
Integer n2 = new Integer(47);
System.out.print(n1= =n2);
System.out.print(“,”);
System.out.println(n1! =n2);
}
}
答案:
- 23 -
flase,true
9. 已有Bird类的定义如下:
package abcde;
public class Bird {
protected static int referenceCount=0;
public Bird(){referenceCount++;}
protected void fly(){ }
static int getReCount(){return referenceCount;}
}
有类Nightingale的定义如下,请写出它的输出结果 。
package singers;
class Nightingale extends abcde.Bird {
Nightingale( ) { referenceCount++;}
public static void main( String args[ ]){
System.out.print(“Before:”+referenceCount);
Nightingale florence=new Nightingale( );
System.out.println(“ After:”+referenceCount);
florence.fly( );
}
}
答案:
Before:0 After:2
10. 以下程序段的输出结果为 。
class Cruncher{
void crunch( int i ){
System.out.println(“int version”);
}
void crunch(String s){
System.out.println(“String version”);
}
public static void main(String args[ ]){
Cruncher crun=new Cruncher ( );
char ch=’p’;
crun.crunch(ch);
} - 24 -
}
答案:
int version
五、 编程题(2道)
1. 试编写程序解下面的问题。猴子吃桃问题:猴子第一天摘下若干个桃子,当即吃了一半,还不瘾,
又多吃了一个第二天早上又将剩下的桃子吃掉一半,又多吃了一个。以后每天早上都吃了前一天剩下的
一半零一个。到第10天早上想再吃时,见只剩下一个桃子了。求第一天共摘了多少。
答案:总共1534个
参考程序如下:
public class MyClass {
public static void main(String[] args) {
int day,x1,x2;
day=9;
x1=0;
x2=1;
while(day>0)
{
x1=(x2+1)*2;/*第一天的桃子数是第2天桃子数加1后的2倍*/
x2=x1;
day=day-1;
}
System.out.println("the total is %d/n"+x1);
}
}
2. 水仙花数是一个三位数,三位数各位的立方之和等于三位数本身。请编写程序,求出所有的水仙花数。
水仙花数为:153,370,371,407
参考程序如下:
public class Test {
public static void main(String[] args) {
int x,y,z;
for(int i=100;i<1000;i++)
{
x=i%10;
y=i/100;
z=(i-y*100)/10;
if(i==(x*x*x+y*y*y+z*z*z)) System.out.println(i);
}
}
}
- 25 -一. 真实考试说明 
1.考试形式:网络计算机 
2.考题形式:多选,单选,简答 
3.题量:60 
4.考试时间:120分钟 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值