java中下面哪句话是正确的_JAVA笔试题选择题

1下面哪个是正确的类声明?假设每一段文本都做为一个名称为Fred.java的文件的全部内容? a

a).

public class Fred{

public int x = 0;

public Fred (int x){

this.x=x;

}

}

b).

public class fred{

public int x = 0;

public Fred (int x){

this.x=x;

}

}

c).

public class Fred extends MyBaseClass, MyOtherBaseClass{

public int x = 0;

public Fred(int xval){

x=xval;

}

}

d).

protected class Fred{

private int x = 0;

private Fred (int xval){

x=xval;

}

}

A. a)

B. b)

C. c)

D. d)

2.在类设计中,类的成员变量要求仅仅能够被同一package下的类访问,请问应该使用下列哪个修辞词 d

A. protected

B. public

C. private

D. 不需要任何修辞词

3.下面那个是Runable接口的方法?a

A. run

B. start

C. yield

D. stop

4.给出类框架如下:

class Example{

private int x;

//rest of class body…

}

假定通过java Example调用x,下列哪个语句能够使得在Example.java的main方法中直接访问x?       b

A. 声明x为public而不是private

B. 声明x为static而不是private

C. 声明x为protected而不是private

D. 声明x为final而不是private

5.给出:以下类

public class ReturnIt{

ReturnType methodA(byte x,double y){

return (short)x/y*2;

}

}

对于在第二行的方法methodA,他的返回值的类型应该是 f

A. int

B. byte

C. long

D. short

E. float

F. double

6.下面列出的那个是java的保留字?                 b

A. if

B. goto

C. while

D. case

E. then

7.十进制变量i的值为12,那么八进制的变量i的值为:                      d

A. O08

B. O10

C. O12

D. O14

E. O16

8.下列哪些说法是正确的?                              d

A. 在collection类树上,最顶层的类叫做Collection

B. collection接口有个方法是enumerator

C. interator方法返回一个Vetor类的实例

D. set接口是为了那些不重复的元素设计的

9.现有下列代码片断:

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"                                                                  c

A. 1或2

B. 1或2或3

C. 2或3

D. 3

E. default

10.public class Test{

public int aMethod(){

static int i=0;

i++;

return i;

}

public static void main(String args[]){

Test test = new Test();

test.aMethod();

int j=test.aMethod();

System.out.println(j);

}

}

结果是什么?                                                    a

A. 编译失败

B. 编译成功和程序打出"0"

C. 编译成功和程序打出"1"

D. 编译成功和程序打出"2"

11. 选择有效的java命名                                                                                 a dA. userName

B. %passwd

C. 3d_game

D. $charge

E. this

12. 变量 "result" 是 boolean类型,下列那些表达式是合法的                             a b

A. result = true;

B. if ( result ) { // do something... }

C. if ( result!= 0 ) { // so something... }

D. result = 1

13。You have the following code. Which numbers will cause "Test2" to be printed?                                                                                                           b c dswitch(x){

case 1:

System.out.println("Test1");

case 2:

case 3:

System.out.println("Test2");

break;

}

System.out.println("Test3");

}

A. 0

B. 1

C. 2

D. 3

E. 4

14. Given the following code:

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) }

Which line will cause error?                                                                    dA. line 3

B. line 6

C. line 7

D. line 8

E. line 10

15.class Parent {

String one, two;

public Parent(String a, String b){

one = a;

two = b;

}

public void print(){ System.out.println(one); }

}

public class Child extends Parent {

public Child(String a, String b){

super(a,b);

}

public void print(){

System.out.println(one + " to " + two);

}

public static void main(String arg[]){

Parent p = new Parent("south", "north");

Parent t = new Child("east", "west");

p.print();

t.print();

}

}

Which of the following is correct?                                                 e

A. Cause error during compilation.

B. south east

C. south to north east to west

D. south to north east

E. south east to west

16.下列代码结果输出多少行?                                                  dpublic class Test {

public static void main(String args[]) {

int[][][] x = new int[3][][];

int j,i;

x[0] = new int[4][];

x[1] = new int[2][];

x[2] = new int[5][];

for(i=0;i

for(j=0;j

x[i][j]= new int[i+j+1];

System.out.println();

System.out.println("size = "+x[i][j].length);

}

}

}

}

A, 8 B, 8 C,   10 D, 11   E, 12

17.Which two statements are true? (Choose two)                              b d

1. class A {

2. A() { }

3. }

4.

5. class B extends A {

6. }

A. Class B’s constructor is public.

B. Class B’s constructor has no arguments.

C. Class B’s constructor includes a call to this().

D. Class B’s constructor includes a call to super().

18. int i = 1,j = 10;

do {

if(i>j) {

break;

}

j--;

} while (++i <5);

System.out.println(“i =” +i+” and j = “+j);                                    dWhat is the result?

A. i = 6 and j = 5

B. i = 5 and j = 5

C. i = 6 and j = 4

D. i = 5 and j = 6

E. i = 6 and j = 6

19.What is the result?                                                             c1. public class Test{

2. public static void aMethod() throws Exception {

3. try {

4. throw new Exception();

5. } finally {

6. System.out.println(“finally”);

7. }

8. }

9. public static void main(String args[]) {

10. try {

11. aMethod();

12. } catch (Exception e) {

13. System.out.println(“exception”);

14. }

15. System.out.println(“finished”);

16. }

17. }

A. finally

B. exception

finished

C. finally

exception

finished

D. Compilation fails.

20.下面那句话跟等于第二行的表达。(Choose three)         a b c 1. public interface Foo {2. int k = 4;                                                                                 3. }A. final int k = 4;B. public int k = 4;C. static int k = 4;D. abstract int k = 4;E. volatile int k = 4;F. protected int k = 4;

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值