SCJP试题三

 

B. float f=-412;

C. int other=(int)true;

D. double d=0x12345678;

E. short s=10;

正确答案: A、B、D、E

 

444. What is the result of executing the following code:

class Test{

public static void main(String args[]){

Test t=new Test();

t.test(1.0,2L,3);

}

void test(double a,double b,short c){

System.out.println("1");

}

void test(float a,byte b,byte c){

System.out.println("2");

}

void test(double a, double b, double c){

System.out.println("3");

}

void test(int a,long b,int e){

System.out.println("4");

}

void test(long a, long b, long c){

System.out.println("5");

}

}

Select the one right answer.

A. 1

B. 2

C. 3

D. 4

E. 5

正确答案: C

 

445. Given these class definitions:

class Superclass{}

class Subclass1 extends Superclass{}

And these objects:

Superclass a=new Superclass();

Suberclass1 b=new Suberclass1();

Which of the following explains the result of the statement:

a=b;

Select the one right amswer.

A. Illegal(不合规定的) at compile time

B. Legal at compile time but possibly illegal at runtime

C. Definitely(明确地) legal at runtime

正确答案: C

 

446. Given these class definitions:

class Superclass{}

class Subclass1 extends Superclass{}

class Subclass2 extends Superclass{}

And these objects:

Superclass a=new Superclass();

Subclass1 b=new Subclass1();

Subclass2 c=new Subclass2();

Which of the following explains the result of the statement:

b=(Subclass1)c;

Select the one right amswer.

A. Illegal at compile time

B. Legal at compile time but possibly illegal at runtime

C. Definitely legal at runtime

正确答案: A

 

447. Given these class definitions:

class Superclass{}

class Subclass1 extends Superclass{}

And these objects:

Supetclass a=new Superclass();

Suberclass1 b=new Suberclass1();

Which of the following explains the result of the statement:

b=a;

Select the one right amswer.

A. Illegal at compile time

B. Legal at compile time but possibly illegal at runtime

C. Definitely legal at runtime

正确答案: A

 

448. Given these class definitions:

class Superclass{}

class Subclass1 extends Superclass{}

And these objects:

Supetclass a=new Superclass();

Subclass1 b=new Subclass1();

Which of the following explains the result of the statement:

b=(Subclass1)a;

Select the one right amswer.

A. Illegal at compile time

B. Legal at compile time but possibly illegal at runtime

C. The code will display the numbers 0 through 99 in the standard output, and then throw an IndexOutOfBoundsException

正确答案: B

 

449. True or false? The default for a floating-point literal(文字的) without an F or a D is a 32-bit float.

Fill in the blank.

正确答案: False

 

450. What output is produced by the following program?

class Test{

public static void main(String args[]){

byte x;

short y=128;      byte   -128~~~~~127   short  -32768~~~~~32767

x=(byte)y;

System.out.println(x + " " +y);

}

}

Select the one right amswer.

A. A compiler error

B. A runtime error

C. 128 128

D. -128 128

正确答案: D

 

 

 

 

 

451. What output is produced by the following program?

class Test{

public static void main(String args[]){

byte x;

short y=128;

x=y;

System.out.println(x + " " +)y;

}

}

Select the one right answer.

A. A compiler error

B. A runtime error

C. 128 128

D. -128 128

正确答案: A

 

452. What output is produced by the following program?

class Test{

public static void main(String args[]){

char x=65;

char y;

y=(char)(2*x);

System.out.println(y);

}

}

Select the one right amswer.

A. A compiler error

B. A runtime error

C. 130

D. ?(symbol(符号) for non-printable character)

正确答案: D

 

453. What output is produced by the following program?

class Test{

public static void main(String args[]){

byte x=-65;

byte y=2;

byte z=(byte)(x*y);

System.out.println(z);

}

}

Select the one right amswer.

A. A compiler error

B. A runtime error

C. -130

D. None of the above

正确答案: D

 

454. What output is produced by the following program?

class Test{

public static void main(String args[]){

int x;

double y=-10.9;

x=(int)y;

System.out.println(x+" ");

y=10.9;

x=(int)y;

System.out.println(x);

}

}

Select the one right amswer.

A. -11 10

B. -11 11

C. -10 10

D. –10 11

正确答案: C

 

455. What output is produced by the following program?

class Test{

public static void main(String args[]){

try{

byte x=64;

byte y=64;

byte z=(byte)(x + y);

System.out.println(z);

}catch(Exception e){

System.out.println("Exception");

}

}

}

Select the one right amswer.

A. A compiler error

B. Exception

C. 128

D. -128

正确答案: D

 

456.What output is produced by the following program?

class Test{

public static void main(String args[]){

try{

byte x=64;

byte y=64;

System.out.println(x + y);

}catch(Exception e){

System.out.println("Exception");

}

}

}

Select the one right amswer.

A. A compiler error

B. Exception

C. 128

D. -128

正确答案: C

 

457. What output is produced by the following program?

class Test{

public static void main(String args[]){

try{

byte x=5;

byte y=x<<2;  

System.out.println(y);

}catch(Exception e){

System.out.println("Exception");

}

}

}

Select the one right answer.

A. A compiler error

B. Exception

C. 5

D. 10

E. 15

F. 20

G. 25

正确答案: A

 

458. What output is produced by the following program?

class Test{

public static void main(String args[]){

try{

byte x=5;

byte y=(byte)(x<<2);

System.out.println(y);

}catch(Exception e){

System.out.println("Exception");

}

}

}

Select the one right answer.

A. A compiler error

B. Exception

C. 5

D. 10

E. 15

F. 20

G. 25

正确答案: F

 

459. What output is produced by the following program?

class Test{

public static void main(String args[]){

try{

byte x=32;

byte y=(byte)(x<<2);

System.out.println(y);

}catch(Exception e){

System.out.println("Exception");

}

}

}

Select the one right amswer.

A. A compiler error

B. Exception

C. 32

D. 64

E. 128

F. 256

G. None of the above  -128

正确答案: G

 

460. What output is produced by the following program?

class Test{

public static void main(String args[]){

try{

byte x=-32;

byte y=(byte)(x>>>2);

byte z=(byte)(x + y);

System.out.println(y);

}catch(Exception e){

System.out.println("Exception");

}

}

}

Select the one right amswer.

A. A compiler error

B. Exception

C. -4

D. -8

E. -16

F. -32

G. None of the above

正确答案: D

 

461.Which of the following assignments are legal?

A. floal a=2.0

B. double b=2.0

C. int c=2

D. long d=2

正确答案: B、C、D

 

 

 

 

462. The Person, Student and Teacher are class names. These classes have the following inheritance relation as shown below:

 

   Person

Student  Teacher

 

There is the following expression in a Java source file:

Person p=new Student();

Which one of the following statements are true?

A. The expression is legal

B. The expression is illegal

C. Some error will correct but it will be wrong when running

正确答案: A

 

463. The person, Student and Teacher are class names. These classes have the following inheritance relation as shown below:

 

   Person

Student  Teacher

 

In Java source file a specific method has an argument. In order to handle all these classes in this method which type of argument of this method should be used?

A. Person

B. Student

C. Tescher

D. Object

E. None of them can be used' Person

正确答案: A、D

 

464. Analyze these two consecutive lines of code:

float f=3.2;

int i=f;

Select all valid answer.

A. this code would not compile

B. this code would compile and i would be set to 3

C. the second line could compile if it were written instead as: int i =(byte)f;

D. the first line could compile if it were written instead as: float f=3.2F;

正确答案: A、C、D

 

 

 

465. What is the final value of temp in this sequence?

long temp=(int)3.9;

temp%=2;

Select the one right amswer.

A. 0

B. 1

C. 2

D. 3

E. 4

正确答案: B

 

466. Which of the following lines will compile without warning or error?

A. float f=1.3;

B. char c="a";

C. byte b=257;

D. boolean b=null;

E. int i=10;

正确答案: E

 

467. Which of the following lines of code will compile without error?

A. int i=0;

if(i){

System.out.println("Hello");

}

B. boolean b=true;

boolean b2=true;

if(b==b2){

System.out.println("So true");

}

C. int i=1;

int j=2;

if(i==1 || j==2)

System.out.println("OK");

D. int I=1;

int j=2;

if(i==1 &| j==2)

System.out.println("OK");

 

正确答案: B、C

 

468. What will be the result when you attempt to compile this program?

public class Test{

public static void main(String args[]){

int iRand;

iRand=Math.random();

System.out.println(iRand);

}

}

Select the one right answer.

A. Compile time error referring to a cast problem

B. A random number between 1 and 10

C. A random number between 0 and 1

D. A compile time error about random being an unrecognized method

正确答案: A

 

469. Which of the following will compile correctly?

A. short myshort = 99s;

B. String name = 'Excellent tutorial Mr Green';

C. char c = 17c;

D. int z=015;

正确答案: D

 

470. Given the following code:

class Base {}

public class Test extends Base{

 static boolean b1 = false;

static int i=-1;

static double d=10.1;

public static void main(String argv[]){

Test m=new Test();

Base b=new Base();

//Here

}

}

Which of the following, If inserted at the comment //Here will allow the code to compile and run without error?

A. b=m;

B. m=b;

C. d=i;

D. b1=i;

正确答案: A、C

 

471. Given the following classes which of the following will compile without error?

interface IFace{}

class CFace implements IFace{}

class Base{}

public class Test extends Base{

public static void main(String argv[]){

Test ob=new Test();

Base b=new Base();

Object o1=new Object();

IFace o2=new CFace();

}

}

Select the one right answer.

A. o1=o2;

B. b=ob;

C. ob=b;

D. o1=b;

正确答案: A、B、D

 

472. Which of the following are legal statements?

A. float f=1/3;

B. int i=1/3;

C. float f=1.01;

D. double d=999d;

正确答案: A、B、D

 

473. Which of the following are valid statements?

A. System.out.println(1+1);

B. int i=2+'2';

C. byte b=255;

正确答案: A、B

 

474. Given the following code:

class Base{}

class Test extends Base{

public String getFields(){

String name="Test";

return name;

}

}

public class DoTest{

public static void main(String argv[]){

Base a=new Test();

//Here

}

}

What code placed after the comment//Here will result in calling the getFields method resulting in the output of the string "Test"?

A. System.out.println(a.getFields());

B. System.out.println(a.name);

C. System.out.println((Base) a.getFields());

D. System.out.println(((Test) a).getFields());

正确答案: D

 

475. What is the result when you compile and run the following code?

byte Byte=10;

byte Double=12;

byte Integer=Byte*Double;

Select the one right answer.

A. 120

B. Compile time error while declaring variables

C. Compile time error while multiplication

D. None of the above

正确答案: C

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/wangjun_pfc/archive/2007/10/13/1823158.aspx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值