资源描述
《Java程序设计》理论题库—选取题(单选175题)
1.欲构造ArrayList类一种实例,此类继承了List接口,下列哪个办法是对的 ? B
A、ArrayList myList=new Object();
B、List myList=new ArrayList();
C、ArrayList myList=new List();
D、List myList=new List();
2.paint()办法使用哪种类型参数?A
A、Graphics
B、Graphics2D
C、String
D、Color
3.指出对的表达式 D
A、byte=128;//byte取值到127
B、Boolean=null;
C、long l=0xfffL;
D、double=0.9239d;
4.指出下列程序运营成果 B
public class Example{
String str=new String("good");
char[]ch={'a','b','c'};
public static void main(String args[]){
Example ex=new Example();
ex.change(ex.str,ex.ch);
System.out.print(ex.str+" and ");
Sytem.out.print(ex.ch);
}
public void change(String str,char ch[]){
str="test ok";
ch[0]='g';
}
}
A、good and abc
B、good and gbc
C、test ok and abc
D、test ok and gbc
5.运营下列程序,会产生什么成果 C D
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、程序会运营和启动
6.要从文献" file.dat"文献中读出第10个字节到变量C中,下列哪个办法适合?A
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();
7.容器被重新设立大小后,哪种布局管理器容器中组件大小不随容器大小变化而变化? B
A、CardLayout
B、FlowLayout
C、BorderLayout
D、GridLayout
8.给出下面代码:
public class Person{
static int arr[] = new int[10];
public static void main(String a[])
{
System.out.println(arr[1]);
}
}
那个语句是对的? C
A、编译时将产生错误;
B、编译时对的,运营时将产生错误;
C 、输出零;
D、输出空。
9.哪个核心字可以对对象加互斥锁? B
A、transient
B synchronized
C serialize
D static
10.下列哪些语句关于内存回收阐明是对的?B
A、程序员必要创立一种线程来释放内存;
B、内存回收程序负责释放无用内存
C、内存回收程序容许程序员直接释放内存
D、内存回收程序可以在指定期间释放内存对象
11.下列代码哪几行会出错:C
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
12.MAX_LENGTH是int型public成员变量,变量值保持为常量100,用简短语句定义这个变量。 D
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.
13.给出下面代码:
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} }
那些行将引起错误? D
A、第3行
B、第6行
C、第7行
D、第8行
14.类Teacher和Student是类Person子类;
Person p;
Teacher t;
Student s;
//p,t and s are all non-null.
if(t instanceof Person) { s = (Student)t;}
最后一句语句成果是: B C
A、将构造一种Student对象;
B、表达式是合法;
C、表达式是错误;
D、编译时对的,但运营时错误。
15.给出下面代码段
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) }
哪行将引起一种编译时错误? D
A、line 3
B、line 5
C、line 6
D、line 10
16.对于下列代码:
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行语句将调用哪行语句??D
A、line 2
B、line 3
C、line 6
D、line 7
17.哪个核心字可以抛出异常? C
A、transient
B、finally
C、throw
D、static
18.Main()办法返回类型是: B
A、int
B、void
C、boolean
D、static
19.System类在哪个包中?D
A、java.util
B、java.io
C、java.awt
D、java.lang
20.对于下列代码:
public class Parent {
public int addValue( int a,int b) {
int s;
s = a+b;
return s;
}
}
class Child extends Parent {
}
下述哪些办法可以加入类Child?C
A、int addValue( int a,int b ){// do something...}
B、public void addValue (int a,int b ){// do something...}
C、public int addValue( int a ){// do something...}
D、public int addValue( int a,int b )throws MyException {//do something...}
21.给出下面代码:
public class test{
static int a[] = new a[10];
public static void main(String args[]) {
System.out.println(a[10]);
}
}
那个选项是对的? A
A、编译时将产生错误;
B、编译时对的,运营时将产生错误;
C、输出零;
D、输出空。
22.下面哪些选项是对的main办法阐明? B
A、public main(String args[])
B、public static void main(String args[])
C、private static void main(String args[])
D、void main()
23.给定下面代码片段: C
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
24.下面哪种注释办法可以支持javadoc命令:B D
A、/**...**/
B、/*...*/
C、//
D、/**...*/
25. 欲编写如下图一种界面,用于显示顾客指定图像:如果在区域A中只能放置一种
AWT组件,从各组件本来功能角度考虑,最佳使用哪种组件:D
A、TextArea
B、Panel
C、Applet
D、Canvas
26. 界面如上题所示。若"Button1"功能是:点击后弹出一种用于输入界面,获取顾客想要显示图像文献名,则该界面最佳是(从编程简朴和程序不易出错角度考虑): c
A、模式(Modal)Dialog
B、非模式(None-modal)Dialog
C、FileDialog
D、Frame
27. 界面如上题所示。如果在A区域使用某种AWT组件(java.awt.Component子类)来负责绘制图像,则绘图语句最佳应放在该组件哪个办法中(考虑到应用程序和Java虚拟机AWT线程都会规定重画该组件)?B
A、构造办法
B、paint(Graphics g)
C、update(Graphics g)
D、repaint()
28.下面关于Applet说法对的是 B
A、Applet也需要main办法
B、Applet必要继承自java.awt.Applet
C、Applet能访问本地文献
D、Applet程序不需要编译
29.看下面一段程序:
class Aclass{
void go(){
System.out.println("Aclass");
}
}
public class Bclass extends Aclass{
void go(){
System.out.println("Bclass");
}
public static void main(String args[]){
Aclass a=new Aclass();
Aclass a1=new Bclass();
a.go();
a1.go();
}
以上程序运营成果是: B C
A、Aclass
Aclass
B、Bclass
Bclass
C、Aclass
Bclass
D、Bclass
Aclass
30.下列关于Java线程说法那些是对的() D
A、每一种Java线程可以当作由代码、一种真实CPU以及数据三部份构成。
B、创立线程两种办法中,从Thread类中继承创立方式可以防止浮现多父类问题。
C、Thread类属于java.util程序包。
D、以上说法无一对的。
31.看如下程序:
boolean a=false;
boolean b=true;
boolean c=(a&&b)&&(!b);
int result=(c= =false)?1:2;
这段程序执行完后,c与result值是: D A
A、c=false;result=1;
B、c=true;result=2;
C、c=true;result=1;
D、c=false;result=2;
32.运营下列程序,会产生什么成果 B
public class X extends Thread implements Runnable{
public void run(){
System.out.println("this is run()");
}
public static void main(String args[])
{
Thread t=new Thread(new X());
t.start();
}
}
A、in the Inner outer
B、this is run()
C、in the Inner
D、编译不通过
33.指出下列程序运营成果 B
int i = 9;
switch (i) {
default:
System.out.println("default");
case 0:
System.out.println("zero");
break;
case 1:
System.out.println("one");
case 2:
System.out.println("two");
}
A、default
B、default,zero
C、error default clause not defined
D、no output displayed那个
34.运营下列程序,会产生什么成果:B
class Outer1{
private int a;
void foo(double d,final float f){
String s;
final boolean b;
class Inner{
void methodInner(){
System.out.println("in the Inner");
}
}
}
public static void main(String args[])
{
Outer1 me=new Outer1();
me.foo(123,123);
System.out.println("outer");
}
}
A、in the Inner outer
B、outer
C、in the Inner
D、编译不通过
35. 下面哪个单词是Java语言核心字( B )
A、Float B、this C、string D、unsigned
36. 下面哪个是Java语言中对的标记符( C )
A、3com B、import C、that D、this
37. 下面哪个语句不能定义一种字符变量( D )
A、char c1=06477; B、char c2=’\uface’ ;
C、char c4=0xbeef ; D、char c3=\u0041;
38. 下面哪个修饰符修饰办法只能被本类中其她办法使用( C )
A、protected B、static C、private D、public
39. 下面哪个运算后成果为32 ( B )
A、2^5 B、(8>>2)<<4 C、2>>5 D、 (2<<1)*(32>>3)
40. 下面哪个是对字符串String正拟定义 ( A )
A、String s1=null; B、String s2=’null’ ;
C、String s3=(String) ‘abc’ ; D、String s4=(String) ‘\uface’;
41. 下面哪条语句不能定义一种float型变量( B )
A、float f1= -343 ; B、float f2=3.14 ;
C、float f3=0x12345 ; D、float f4=2.8F ;
42. 下面哪条语句定义了5个元素数组( A )
A、int [] a={22,23,24,25,12};
B、int a []=new int(5);
C、int [5] array;
D、int [] arr;
43. 下面哪个范畴是char型取值范畴( c )
A、-256 ~ 255 B、-(2^15) ~ (2^15)-1 C、’\u0000’ ~ ‘\uffff’ D、 0~3276
44. 给出一段程序,选取运营成果( D )
public class sss {
public static void main(String args[])
{
String s1=args[1]; String s2=args[2];
String s3=args[3]; String s4=args[4];
System.out.println(“args[2]=”+s2);
}
}
命令行执行: java sss 1 2 3 4 成果是下面哪一种?
A、args[2]=2 B、args[2]=null C、args[2]=1 D、运营浮现异常
45. 下面哪个描述是对的( A )
A、Applet程序中不需要main()办法,也不能有
B、Application程序中可以没有main()办法。
C、Applet程序中可以不定义init( )办法
D、Application程序中必要有run( )办法
46. 给出一段程序,试判断哪个是对的成果( B )
public class rtExcept{
public static void throwit(){
System.out.print(“throwit”);
throw new RuntimeException(); }
public static void main(String [] aa){
try{
System.out.print(“hello “);
throwit();}
catch(Exception re){
System.out.print(“caught ”); }
finally{
System.out.print(“finally ”);}
System.out.print(“after ”);
}
}
A、hello throwit caught
B、hello throwit caught finally after
C、hello throwit RuntimeException after
D、hello throwit caught finally after RuntimeException
47. 对一种java源文献 aaa.java,编辑保存后但未编译,在其所在目录下执行 java aaa,则接着会浮现什么( C )
A、error:cannot read:aaa.java
B、无任何显示
C、Exception in thread "main" java.lang.NoClassDefFoundError:aaa
D、程序正常执行并显示
48. 编译java程序时浮现error:cannot read:aaa.java,则下列因素最对的是( A )
A、因素是执行当前目录下没有找到aaa.java文献。
B、因素是没有安装JDK开发环境。
C、因素是java源文献名后缀一定是以 .txt 结尾。
D、因素是JDK安装后没有对的设立环境变量PATH和Classpath 。
49. 给出一段程序,试判断哪个是对的成果( D )
public class myprogram{
public static void main (String args[]){
try{
System.out.print(“Hello world ”);}
finally{
System.out.println(“Finally executing”);
}
}
}
A、无法编译,由于没有指定异常
B、无法编译,由于没有catch子句
C、Hello world
D、Hello world Finally executing
50. 下面哪个是Java语言中对的标记符( B )
A、3D B、$this C、extends D、implements
51. 下面哪个范畴是char型取值范畴( C )
A、-256 ~ 255 B、-(2^15) ~ (2^15)-1 C、’\u0000’ ~ ‘\uffff’ D、 0~32767
52. 下面哪个语句不能定义一种字符变量( D )
A、char c1=3210; B、char c2=’\uface’ ;
C、char c4=0xabcd ; D、char c3=”\u0065”;
53. 下面哪个是对字符串String正拟定义 ( A )
A、String s1=”\n\t null”; B、String s2=’null’ ;
C、String s3=(String) ‘abc’ ; D、String s4=(String) ‘\uface’;
54. 给出下面一段程序,选取运营成果( C )
public class X{
public static void main(String [] args){
String names[]=new String[5];
for(int x=0;x<args.length;x++) names[x]=args[x];
System.out.println(names[2]);
}}
命令行执行: java X a b 成果是下面哪一种?
A、names B、b C、null D、 运营浮现异常
55. 下面哪个描述是对的( A )
A、Applet程序中不需要main()办法,也不能有
B、Application程序中可以没有main()办法。
C、Applet程序中可以不定义init( )办法
D、Application程序中必要有run( )办法
56. 下面哪项可以得到数组元素个数,java中定义数组名为 abc,( B )
A、abc.length( ) B、abc.length C、len(abc) D、ubound(abc)
57.下面哪个修饰符修饰变量是所有同一种类生成对象共享( C )
A、public B、private C、static D、final
58. 给出一段程序,试判断哪个是对的成果( D )
public class myprogram{
public static void main (String args[]){
try{ System.out.print(“Hello world ”);}
finally{
System.out.println(“Finally executing”);} } }
A、无法编译运营,由于没有指定异常
B、无法编译运营,由于没有catch子句
C、Hello world
D、Hello world Finally executing
59.下面关于java中类说法哪个是不对的( C )
A、类体中只能有变量定义和成员办法定义,不能有其她语句。
B、构造函数是类中特殊办法。
C、类一定要声明为public,才可以执行。
D、一种java文献中可以有各种class定义。
60. 下面程序运营后输出成果为( c )
class A
{static int y=6;
void showy( ){System.out.println(“y=”+y);} }
class testA
{
public static void main(String aaa [])
{ A a1=new A( );
A.y+=1; a1.y++;
a1.showy( );
}
}
输出成果选取:
A、y=6; B、y=7; C、y=8; D、程序运营出错
61. 编译java程序时浮现error:cannot read:aaa.java,则下列因素最对的是( A )
A、因素是执行当前目录下没有找到aaa.java文献。
B、因素是没有安装JDK开发环境。
C、因素是java源文献名后缀一定是以 .txt 结尾。
D、因素是JDK安装后没有对的设立环境变量PATH和Classpath 。
62. 下面关于构造函数说法不对的是( B )
A、构造函数也属于类办法,用于创立对象时候给成员变量赋值。
B、构造函数不可以重载。
C、构造函数没有返回值。
D、构造函数一定要和类名相似。
63. 在java一种异常解决中,哪个语句块可以有各种 ( A )
A、catch B、finally C、try D、throws
64. 对一种java源文献 aaa.java,编辑保存后但未编译,在其所在目录下执行 java aaa,则接着会浮现什么( C )
A、error:cannot read:aaa.java
B、无任何显示
C、Exception in thread "main" java.lang.NoClassDefFoundError:aaa
D|、程序正常执行并显示
65.下面表达式中,用来访问数组中第一种值是__C__
A、intArray[1] B、intArray.1 C.intArray[0] D、intArray.0
66.监听事件和解决事件 B
A、都由Listener完毕 B、都由相应事件Listener处登记过构件完毕
C、由Listener和构件分别完毕 D、由Listener和窗口分别完毕
67.如果但愿所有控件在界面上均匀排列,应使用下列那种布局管理器? B
A、BoxLayout B、GridLayout C、BorderLayout D、FlowLayout
68.给出如下代码:
class Test{
private int m;
public static void fun() {
// some code...
}
}
如何使成员变量m 被函数fun()直接访问? C
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
69.下面代码段中,执行之后i 和j 值是什么? C
int i = 1;
int j;
j = i++;
A、1,1 B、1,2 C、2,1 D、2,2
70.欲构造ArrayList类一种实例,此类继承了List接口,下列哪个办法是对的 ? B
A、ArrayList myList=new Object();
B、List myList=new ArrayList();
C、ArrayList myList=new List();
D、List myList=new List();
71.paint()办法使用哪种类型参数? A
A、Graphics
B、Graphics2D
C、String
D、Color
72.指出对的表达式 C
A、byte=128;
B、Boolean=null;
C、long l=0xfffL;
D、double=0.9239d;
73.指出下列程序运营成果 D
public class Example{
String str=new String("good");
char[]ch={'a','b','c'};
public static void main(String args[]){
Example ex=new Example();
ex.change(ex.str,ex.ch);
System.out.print(ex.str+" and ");
Sytem.out.print(ex.ch);
}
public void change(String str,char ch[]){
str="test ok";
ch[0]='g';
}
}
A、good and abc
B、good and gbc
C、test ok and abc
D、test ok and gbc
74.运营下列程序,会产生什么成果 A
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、程序会运营和启动
75.要从文献" file.dat"文献中读出第10个字节到变量C中,下列哪个办法适合?A
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();
76.容器被重新设立大小后,哪种布局管理器容器中组件大小不随容器大小变化而变化? B
A、CardLayout
B、FlowLayout
C、BorderLayout
D、GridLayout
77.给出下面代码: C
public class Person{
展开阅读全文