第一部分 JAVA语言基础
一、 选择题
1、 若所用变量都以正确定义,一下选项中,非法的表达式是C
A a!=4||b==1
B ‘a’%3
C ‘a’=1/2
D ‘A’+32
2、 下列语句序列执行后,j的值是
A 5
B 6
C 7
D 8
3、 java语言的类间的继承关系是B
A 多重的
B 单重的
C 线程的
D 不能继承
4、 下列定义中,不正确的是 C
A class x{…}
B class x extends y {…}
C static class x implements y1,y2{…}
D public class x extends Applet{…}
5、 定义java Applet程序时,必须有的import语句是A
A import java.applet.Applet;
B import java.io.*
C import java.awt.event;
D import java.lang.*;
6、 下列方法定义中,不正确的是D
A public int x( ){…}
B public static int x(double y){…}
C void x (double d){…}
D public static x (double a){…}
7、 下列的哪个选项可以正确表达八进制8 C
A 0x8
B 0x10
C 08
D 010
8、下列关于继承的哪项叙述是正确的C
A 在java中允许多重继承
B 在java中一个类只能实现一个接口
C 在java中一个类不能同时继承一个类和实现一个接口
D java的单一继承使代码更可靠字串1
9、若已定义byte[]x={11,22,33,-66};其中0<=k<=3,则对x数组元素错误的引用时 c
A x[5-3]
B x[k]
C x[k+5]
D x[0]
10、给出下列代码,如何是成员变量m被方法fun()直接访问 -----成员变量在类中定义,局部变量在方法中定义 C
Class test
{
Private int m;
Public static void fun()
{
…
}
}
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
11、Given: F
1 public class Alphal{
2 public static void main(String[] args){
3 boolean flag; int i=0;
1 do{
2 flag = false;
3 system.out.println(i++);
4 flag = 1 < 10
5 continue;
6 }while((flag)?True;false);
7 }
8 }
What is result?
A 0000000000
B 0123456789
C Compilation fails
D The code runs with no output.
E The code enters an infinite loop
F An exception is thrown at runtime e.
12、Given() D
1 package foo;
2
3 import java.Util.Vector;
4
5 protected class MyVector Vector{
6 int i=1;
7 public MyVector()
8 i=2 ;
9 }
10 }
11
12 public class MyNewVector extends MyVector{
13 public MyNewVector(){
14 i=4;
15 }
16 public static void main(String args[]){
import语句17 MyVector v=new MyNewVector
18 }
19 }
what is the result?()
A. Compilation succeeds
B. Compilation falis because of an error at line5
C. Compilation falis because of an error at line6
D. Compilation falis because of an error at line14
E. Compilation falis because of an error at line17
13、Given:()
1 class Super{
2 public integer getlength(){
3 return new integer(4);}
}
4
5 public class Sub extends Super}
6 public Long GetLength(){return new Long(5);}
7
8 public static void main(String[] args){
9 Super sooper = new Super();
10 Sub sub = new Sub();
11 System.out.println(
12 Length().toString()+","+
13 Length().toString() );
14 }
15 }
What is the output?
A.4,4
B.4,5
C.5,4
D.5,5
E.Compilation fails.
14、Given:
1 public class Test{
2 public static String output=....;
3
4 public static void foo (int){
5 try{
6 if(i==1){
7 throw new Exception();
8 }
9 output+="2";
10 }
11 Catch(Exception e){
12 OutPut+="1";
13 Return;
14 }
15 Finally{
16 Output+="3";
17 }
18 Output+="4"
19 }
20
21 Public static void main(string args[]){
22 Foo(0);
23 Foo(1);
24
25 }
26 }
What is the value of the variable output at line 23?
15、Given:() D
1 class Base{
2 Base(){System.out.print("Base");}
3 }
4 public class Alpha extends Base{
5 public static void main(String []args){
6 new Alpha();
7 new Base();
8 }
9 }
What is the result?
A. Base
B. Basebase
c. Compilation fails.
D. The code runs with no output.
E. An exception is thrown at runtime.
16、Given:
1 int l=1,j=-1;
2 switch(i){
3 case 0,1:j=1;
4 case 2;j=2;
5 default;j=0;
6 }
7 System.out.println("j="+j);
What is the result?
A.j=-1
B.j=0
C.j=1
D.j=2
E.Compilation fails.
---------------17、Which two are valid declarations within an interface definition?(Choose two)
A. void methoda();
B. public double methoda();
C. public final double methoda();
D. static void methoda(double dl);
E. Protected void methoda(double dl);
18、Which two allow the class Thing to be instantiated using new Thing()?(Choose two)
A. public class thing{}
B. public class thing{public thing(){}}
C. public class thing{public thing(void){}}
D. public class thing{public thing(String s){} }
E. public class thing{public thing(){} public thing(String s){} }
19、Given:
1 public class X{
2 public static void main(String[] args){
3 try{
4 badMethod()
5 System.out.print(“A”);
6 }
7 catch (Exception ex){
8 System.out.print(“B”);
9 }
10 Finally{
11 System.out.print(“C”);
12 }
13 System.out.print(“D”);
14 }
15 public static void badMethod(){
16 throw new RuntimeException();
17 }
18 }
What is the result?
A. AB
B. BC
C. ABC
D. BCD
E. Compilation fails
20、 Given:
1 class TestA{
2 TestB b;
3 TestA() {
4 b = new testB(this);
5 }
6 }
7 class TestB {
8 TestA a;
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论