资源描述
Java模拟试题
共三大题
一、单项选择题(1*60,共计60分)
1.对象之间的基本关系是:
A.包含 继承
B.包含 继承 关联
C.包含 关联
D.没有
2.下列说法正确的是:
A.“清华大学”是一个类
B.“大学”是一个类
C.“大学“和”清华大学“之间是继承的关系
D.“大学“和”清华大学“之间没有关系
3.面向对象程序设计方法的优点:
A.可重用性、可扩展性、可操作性
B.可重用性、可维护性、可操作性
C.可管理性、可扩展性、可操作性
D.可重用性、可扩展性、可管理性
4.下面那一项不会出现编程错误:
A.忘记多行注释符的一个定界符
B.一个标识符的大小写字母使用不当
C.括号不成对出现
D.在一个显示图形用户界面的应用程序中调用System .exit
5.下面这些标识符那些是错误的:
A.MyGame
B._isHers
C.2JavaProgram
D.+$abc
6.所有的程序均可以用几种类型控制结构编写:
A.顺序结构、选择结构、循环结构
B.顺序结构、循环结构
C.顺序结构、选择结构
D.选择结构、循环结构
7.当条件为真和条件为假时,▁▁控制结构可以执行不同的动作。
A.switch
B.while
C.for
D.if/else
8.当事先不知道语句重复执行的次数时,可以用一个▁▁值来终止循环。
A.布尔
B.正
C.标记
D.负
9.请看下面的程序代码:
if(x>0) { System .out .println(“first”);}
else if(x<10) { System .out .println(“second”);}
else { System .out .println(“third”) }
当程序输出“second”时,X的范围为:
A.x < = 0
B.x < 10 && x > 0
C.x > 0
D.x >= 10
10.线性表和表可以存储在▁▁中。
A.数组
B.堆栈
C.文件
D.字符串
11.二维数组使用几个下标。
A.1
B.2
C.3
D.4
12.请看下面的程序段
class Person {
String name,department;
int age;
public Person(String n) { name = n; }
public Person(String n,int a) { name = n; age = a; }
public Person(String n,String d,int a) {
//doing the same as two arguments version of constructer
//including assignment name=n,age=a
}
}
下面那一选项可以添加到“//doing the same……”处:
A.Person(n,a)
B.this(Person(n,a))
C.this(n,a)
D.this(name.age)
13.▁▁是一个特殊的方法,用于对类的实例变量进行初始化。
A.终止函数
B.构造函数
C.重载函数
D.初始化函数
14.关键字▁▁表明一个对象或变量在初始化后不能修改。
A.extends
B.final
C.this
D.finalizer
15.声明为static的方法不能访问▁▁类成员。
A.超类
B.子类
C.非static
D.用户自定义类
16.如果超类不允许其通过继承的方式产生的子类访问它的某些成员,那么它必须以什么方式声明该成员。
A. public
B. private
C. protected
D. static
17.如果在你的类的层次结构的类中定义了finalize方法,它总是被定义为什么类型以便子类能访问该方法。
A. public
B. private
C. protected
D. static
18.声明为final的变量不能在子类中覆盖,声明为( )和( )的方法是隐式的final。
A. public private
B. private protected
C. protected static
D. static private
19.使用多态性减少了▁▁逻辑的使用。
A.for
B.while
C.if
D.switch
20.在运行时才确定调用那一个方法,这叫做▁▁绑定。
A.静态
B.动态
C.自动
D.快速
21.请看下面的代码
String s1=new String(“hello”);
String s2=new String(“there”);
String s3=new String( );
下面选项中语句正确的是:
A.s3=s1+s2;
B.s3=s1-s2;
C.s3=s1&s2;
D.s3=s1&&s2;
22.请看下面的代码
public class StrEq{
public static void main(String argv[ ]){
StrEq s = new StrEq( );
}
private StrEq( ){
String s = “Marcus”;
String s2 = new String(“Marcus”);
If(s == s2){
System .out .println(“we have a match”);
}else{
System .out .pritln(“Not equal”);
}
}
}
A.由于使用“private StrEq”编译时会出现错误
B.输出“we have a match”
C.输出“Not equal”
23.跳过try块的异常处理程序,程序在最后一个▁▁块后开始执行。
A.finally
B.catch
C.finally或catch
D.任意
24.▁▁对象一般是Java系统中的严重问题。
A.Error
B.Exception
C.Throwable
D.任何
25.下面选项中,Java对类Welcome进行定义正确的是:
A.public class 1Welcome
B.public class We lcome
C.public class welcome
D.public class Welcome
26.有如下的程序:
public class Welcome3
{
public static void main( String args[] )
{
System.out.println( "Welcome\nto\nJava\nProgramming!" );
}
}
则它的输出结果是:
A.Welcome to Java Programming!
B.WelcomentonJavanProgramming!
C.Welcome
to
Java
Programming
!
D.Welcome
to
Java
Programming!
27.采用类名后跟一点(.)和方法名的形式调用什么方法?
A.静态
B.动态
C.静态和动态
D.任何
28.请选择下面那一条语句是正确的:
A. if ( c < 4 )
JoptionPane.showMessageDialog( null,“c is less than 4 ”);
B. if ( c < 4 );
JoptionPane.showMessageDialog( null,“c is less than 4 ”);
C. if ( c < 4 )
JoptionPane.showMessageDialog( null,“c is less than 4 ”)
D. if ( c = < 4 )
JoptionPane.showMessageDialog( null,“c is less than 4 ”);
29.对方法main的第1行定义正确的是:
A. public main( String arg [ ] )
B. public void main( String arg [ ] )
C. public static void main( String arg [ ] )
D. public static void main( String args [ ] )
30.使整值变量X加1,下面写出的形式不对的是:
A.x + +
B.+ + x
C.x = x + 1
D.x = + 1
31.下面程序的输出结果是:
public class Test{
void printValue(int m){
do { System .out .println(“The value is”+m);
}
while(- - m>10);
}
public static void main(String arg[]){
int I=10;
Test t= new Test();
t.printValue(i);
}
}
A.8
B.9
C.10
D.11
32.下面程序的那一行可能引发错误:
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.4
B.6
C.7
D.8
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.1
B.2
C.5
D.8
34.如果result是布尔变量,下面哪个选项是正确的:
A.result = true;
B.if(result){//do something…}
C.if(result!=0){//do something…}
D.result = 1;
35.请看下面的程序段:
public class Person{
static int arr[] = new int[10];
public static void main(String a[]) {
System .out .println(arr[1]);
}
}
下面说法正确的是:
A.当编译时会发生错误
B.编译不会发生错误但执行是会发生错误
C.输出结果为0
D.不会输出结果
36.请看下面的程序段:
public class Person{
int arr[] = new int[10];
public static void main(String a[]) {
System .out .println(arr[1]);
}
}
下面说法正确的是:
A.当编译时会发生错误
B.编译不会发生错误但执行是会发生错误
C.输出结果为0
D.不会输出结果
37.下面哪个选项正确的声明一个字符型数组:
A.char str[]
B.char str[][]
C.String str[]
D.String str[10]
38.请看下面的程序段:
public class MyClass {
public static void main(String arg[ ]) {
int arr[ ]= new int[3];
System .out .println(“it is “+ arr[1]);
}
}
当编译和执行这段代码时会出现:
A.有一个编译错误为“possible reference before assignment”
B.有一个编译错误为“illegal array declaration syntax”
C.有异常出现为“NullPointerException”
D.正确执行并且输出0
39.请看下面的程序段
class Test{
private int m;
public static void fun(){
//some code…
}
}
方法fun()如何来访问变量m:
A.将private int m改成protected int m
B.将private int m改成public int m
C.将private int m改成static int m
D.将private int m改成int m
40.在Java中,方法main()将返回一个▁▁值。
A.String
B.int
C.char
D.void
41.请看下面的程序段
int i = 1;
int j;
j = i++
在程序段运行后,i和j的值为:
A.1,1
B.1,2
C.2,1
D.2,2
42.请看下面的程序段
public class Test {
long a[ ] = new long[10];
public static void main(String arg[ ]) {
System .out .println(a[6]);
}
}
那一个选项是正确的:
A.不输出任何内容
B.输出0
C.当编译时有错误出现
D.当运行时有错误出现
43.继承性使▁▁成为可能,它不仅节省开发时间,而且也鼓励人们使用已经验证无误和调试过的高质量软件。
A.节省时间
B.软件复用
C.软件管理
D.延长软件生命周期
44.如果Alpha类继承Beta类,Alpha类被称为▁▁类。
A.超类
B.子类
C.系统
D.用户自定义
45.在上题中,Beta类被称为▁▁类。
A.超类
B.子类
C.系统
D.用户自定义
46.一个▁▁类的对象可以当作相应的▁▁类对象看待。
A.子 系统
B.用户 系统
C.子 超
D.超 用户
47.请看下面的代码
1.class Example {
2. String str;
3. public Example( ){
4. str = “example”;
5. }
6. public Example(String s){
7. str = s;
8. }
9..}
10.class Demo extends Example {
11.}
12.public class Test{
13. public void f(){
14. Example ex = new Example(“good”);
15. Demo d = new Demo(“Good”);
16. }
17.}
那一行将导致发生错误:
A.3
B.6
C.10
D.14
E.15
48.请看下面的代码
public class Example{
String str = new String(“hello”);
Char ch[ ]={‘d’,’b’,’c’};
public static void main(String args[ ]){
Example ex=new Example( );
ex.change(ex.str,ex.ch);
System .out .println(ex.str +“and”+ex.ch);
}
public void change(String str,char ch[ ]){
str=”world”;
ch[0]=’a’;
}
}
该程序的输出结果是:
A.hello dbc
B.hello abc
C.world dbc
D.world abc
49.下面选项正确的是:
A.String temp[ ]= new String{“j””a””z”};
B.String temp[ ]= {“j””a””z”};
C.String temp= {“j”,”a”,”z”};
D.String temp[ ]= {“j”,”a”,”z”};
50.▁▁块可以防止资源泄露。
A.finally
B.catch
C.finally或catch
D.任意
51.下面选项中的异常处理不是Java中预定以好的:
A.ArithmeticException
B.NullPointerException
C.SecurityException
D.ArrayOutOfLengthException
E. NegativeArraySizeException
52.用什么来声明一个出来处理:
A.try
B.catch
C.throw
D.finally
53、下列哪一种布局管理器将容器分为“东、西、南、北、中”五个部分?( )
A. FlowLayout B. BorderLayout C. GridLayout D. CardLayout E. GridBagLayout
54、关于Applet的生命周期正确的说法有( )。
A. init()方法在start()方法之后执行 B. init()方法可执行多次
C. stop()方法在Applet退出时被调用,只调用一次
D. stop()方法在Applet不可见时被调用,可以被调用多次
55、实现下列哪个接口可以对 TextField 对象的事件进行监听和处理? ( )
A. MouseMotionListener B. FocusListener C. ActionListener D. WindowListener
56、监听事件和处理事件( )。
A. 都由 Listener 完成 B. 由 Listener 和窗口分别完成
C. 由 Listener 和组件分别完成 D. 都由相应事件 Listener 处登记过的组件完成
57、下面语句正确的是:( )
A. RandomAccessFile raf = new RandomAccesssFile(“myfile.txt”,”rw”)
B. RandomAccessFile raf = new RandomAccesssFile(new DataInputStream())
C. RandomAccessFile raf= new RandomAccesssFile(“myfile.txt”)
D. RandomAccessFile raf = new RandomAccesssFile(new File(“myfile.txt”))
58、( )类是java.lang包中的一个专门用来创建线程和对线程进行操作的类。
A. Runnable B. Thread C. Synchronized
59、Java Application程序执行的入口是( )方法。
A.init() B. main() C.stop() D.start()
60、Java Applet程序执行的入口是( )方法。
A.init() B. main() C.stop() D.start()
二、多重选择题(2*20,共计40分)
1.请看下面的程序代码:
switch(n) {
case 0: System .out .println(“first”);
case 1:
case 2: System .out .println(“second”); break;
default: System .out .println(“end”);
}
当n为何值时,程序段将输出字符串second:
A.0
B.1
C.2
D.3
2.数组元素之所以相关,是因为它们具有相同的▁▁。
A.名字
B.类型
C.下标
D.地址
3.请看下面的程序段
public class Person{
String name;
int age;
public Person(String n,int a)
{ name=n;
age=a;}
public static void main(String arg[ ]){
//point x
}
}
下面选项可以添加到//point x处:
A.Person p[ ]=new Person[3];
P[1]=new Person(“user1”;24);
B.Person p[ ];
P=new Person[3];
P=new Person(“user2”;56);
C.Person p[ ]={ new Person(“user1’,34),(“user2”,34)}
D.Person p[ ]=new Person{(“user1’,34),(“user2”,34)}
4.请看下面的程序段
public class Test{
String s;
int m;
public Test(String t ,int n){
s=t;m=n;
}
public static void main(String arg[ ]){
Test t[ ]={ new Test(“abc”,3);
new Test(“ddf”,23) };
//point x
}
}
下面选项可以添加到//point x处:
A.System .out .println(“the value is”+t[3].s);
B.System .out .println(“the value is”+t[2].m);
C.System .out .println(“the value is”+t[1].s);
D.System .out .println(“the value is”+t[1].m);
5.下面那一个不是Java的关键字:
A. TRUE
B. sizeof
C. const
D. super
E. void
6.下面语句书写错误的是:
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”;
7.请看下面的代码
String s = “hello”;
String t = “hello”;
String c[ ] = {‘h’,’e’,’l’,’l’,’o’};
下面哪一选项的语句返回值为真:
A.s .equals(t);
B.t .equals(c);
C.s==t;
D.t .equals(new String(“hello”));
E. t==c;
8.请看下面的代码
String s = “story”;
下面选项语句书写正确的是:
A.s += “books”;
B.char c = s[1];
C.int len = s .length;
D.String t = s.toLowerCase( );
9.使用catch(Exception e)的好处是▁▁。
A.只会捕获个别类型的异常
B.捕获try块中产生的所有类型的异常
C.不会漏掉所产生的异常
D.执行一些程序
10.请看下面的代码
public void test( ) {
try { oneMethod( );
System .out .println(“condition 1”);
} catch (ArrayIndexOutOfBoundsException e) {
System .out .println(“condition 2”);
catch (Exception e) {
System .out .println(“condition 3”);
} finally {
System .out .println(“condition 4”);
}
}
如果oneMethod抛出NullPointerException,则程序输出结果为:
A.condition 1
B.condition 2
C.condition 3
D.condition 4
11. 请看下面的代码
public void fun( )
{
int i;
try
{
i=System .in .read( );
System .out .println(“location 1”);
} catch (IOException e) {
System .out .println(“location 2”);
} finally {
System .out .println(“location 3”);
}
System .out .println(“location 4”);
}
如果IOException块执行,程序的输出结果为:
A.location 1
B.location 2
C.location 3
D.location 4
12.下面那一个选项正确创建一个空的含有6个元素的字符数组:
A.String s[6];
B.String [6]s;
C.String s[ ]={“”,””,””,””,””,””};
D.String s[ ]=new String[6];
For(int m=0;m<6;m++) { s[m]=””;}
E. String s[ ]=new String[6];
For(int m=0;m<6;m++) { s[m]=null;}
13.关于变量和它们范围的说法,正确的是:
A.实例变量是类的成员变量
B.实例变量要用关键字static来声明
C.在一个方法执行时,定义在该方法的局部变量才被创建
D.局部变量必须在它们使用前初始化
14.四种成员访问形式是▁▁。
A.public
B.private
C.protected
D.包访问
15.下面选项正确创建一个字符型数组(含有4个元素)的是:
A.String a[ ] = new String[4];
for(int i=0;i<4;a[i++]=””);
B.String a[ ]={“”,””,””,””};
C.String a[4];
D.String [4]a;
E. String [ ]a = new String[4];
For(int i=0;i<4;a[i++]=null);
16.请看下面的代码
1.StringBuffer sb = new StringBuffer(“abc”);
2.String s = new String(“abc”);
3.sb.append(“def”);
4.s.append(“def”);
5.sb.inser(1,”zzzz”);
6.s.concat(sb);
7.s.trim( );
下面说法正确的是:
A.编译时在第一行发生一个错误
B.编译时在第二行发生一个错误
C.编译时在第三行发生一个错误
D.编译时在第四行发生一个错误
E. 编译时在第五行发生一个错误
F. 编译时在第六行发生一个错误
G. 编译时在第七行发生一个错误
17、下列程序段执行后t5的结果是( )。
int t1 = 9, t2 = 11, t3=8;
int t4,t5;
t4 = t1 > t2 ? t1 : t2+ t1;
t5 = t4 > t3 ? t4 : t3;
A.8 B.20 C.11 D.9
18、请看下面的代码。如果oneMethod抛出NullPointerException,则程序输出结果为( )。
public void test( ) {
try { oneMethod( ); System .out .println(“condition 1”); }
catch (ArrayIndexOutOfBoundsException e){ System .out .println(“condition 2”);}
catch (Exception e) { System .out .println(“condition 3”);}
finally { System .out .println(“condition 4”); } }
A.condition 1 B.condition 2 C.condition 3 D.condition 4
19.请看下面的代码
public void test( ) {
try { oneMethod( );
System .out .println(“condition 1”);
} catch (ArrayIndexOutOfBoundsException e) {
System .out .println(“condition 2”);
catch (Exception e) {
System .out .println(“condition 3”);
} finally {
System .out .println(“finally”);
}
}
如果oneMethod正常运行,则程序输出结果为:
A.condition 1
B.condition 2
C.condition 3
D.finally
20.请看下面未完成的代码
1.
2.{ success = connect( );
3. if(success==-1) {
4. throw new TimedOutException( );
5. }
6.}
其中TimedOutException不是运行时间异常,则在第1行需要添加那一条语句来完成方法的声明:
A.public void method( )
B.public void method( )throws Exception
C.public void method( )throws TimedOutException
D.public void method( )throw TimedOutException
E. public throw TimedOutException void method( )
展开阅读全文