现在的位置: 首页 > 综合 > 正文

SCJP考题十

2014年01月15日 ⁄ 综合 ⁄ 共 16515字 ⁄ 字号 评论关闭

10.What output is produced by the following program?

class Test{

public static void main(String args[]){

long size=10;

int[] array=new int[size];

size=20;

System.out.println(array.length);

}

}

Select the one right answer.

A. A compiler error.

B. A runtime error.

C. 10

D. 20

正确答案:A

 

11. What output is produced by the following program"

class Test{

public static void main(String args[]){

char size=10;

int[] array=new int[size];

size=20;

System.out.printiln(array.length);

}

}

Select the one right answer.

A. A comoiler error.

B. A runtime error.

C. 10

D. 20

正确答案:C

 

12. True or false? Elemint values in Java arrays are automatically initialized when the arrays is constructed using the new operator.

Fill in the blank.

正确答案:Thue

 

13. When an array of char elements is constructed, the elements are automatically initialized to which of the following values:

A. '0'

B. '/u0000'

正确答案:B

 

14. What output is produced by the following program?

class Test{

public static void nain(String args[]){

char[] a1={'u/0030','/u0031'};

System.out.println(a1[1]);

}

}

Select the one right answer.

A. A compiler error

B. A runtime error

C. 30

D. 31

E. 0

F. 1

正确答案: F

 

15. What output is produced by the following program? (Note the placeholder comma in the boldface portion.)

class Test{

public static void main(String args[1]){

char[] a1={'u/0030', , '/u0031'};

Sysem.out.println(a1[0]);

}

}

Select the one right answer.

A. A compiler error

B. A runtime error

C. 0

正确答案:A

 

16. What is the name of the property of an array object that always contains the size of the array and how may it be used?

Fill in the blank

正确答案:length

 

 

17. True or false? All Java applications and applets require a main() method.

Fill in the blank.

正确答案:False

 

18. Show six different ways to express the decimal value 28 as an integral literal.

Fill in the blank.

正确答案:28,034, 0x1c, 0x1C, 0X1c, 0X1C

 

19. True false? By default, an integral literal is a 64 bit value

Fill in the blank.

正确答案:False

 

 

240. What output is produced by the following program?

class Test{

public static void main(String args[]){

try{

int x=64;

int y=0;

System.out.println(x%y);

}catch(Exception e){

System.out.println("Exception");

}

 }

}

Select all of the right answers from the flowing

A. A compiler error

B. Exception

C. Infinity

D. NaN

正确答案:B

 

241. What output is produced by the following program?

class Test{

public static void main(sString args[]){

System.out.println(Double.isNaN(3.0%0));

System.out.print("");

System.out.println(Double.isNaN(3.0/0));

}

}

Select of the right answers.

A. false false

B. false ture

C. ture false

D. true true

正确答案:C

 

242. What output is produced by the following program?

class Test{

public static void main(String args[]){

try{

double x=64.0;

double y=0.0;

System.out.println(x%y==x%y);

}cateh(Exception e){

System.out.println("Exception");

}

}

}

Select all of the right answers from the flowing

A. A compiler error

B. Exception

C. true

D. fatse

正确答案:D

 

243. What output is produced by the following program?

class Test{

public static void main(String args[]){

try{

System.out.println(Float.NaN==Float NaN);

System.out.println(""+

(Float.POSITIVE.INFINITY==Float.POSITIVE_INFINITY));

}catch(Exception e){

System.out.println("Exception");

}

}

}

Select all of the right answers

A. A compiler error

B. Exception

C. true true

D. fatse false

正确答案:D

 

244. What is the operator for the bit shift and rotate operation in Java?

Fill in the blank.

正确答案:There is no bit shift and rotate operator.

 

245. True or faise? Integer division by zero, including a modulo(%) operation results in an ArithmeticException. No other arithmetic operation in Java can throw an exception. Instead, all other arithmetic operations proceed to a result, even though that result might be arithmetically incorrect.

Fill is the blank.

正确答案:Ture

 

246. 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 all of the right answers from the flowing.

A. A compiler error

B. Exception

C. -4

D. -8

E. -16

F. -32

G. None of the above

正确答案: D

 

247. What output is produced by the following program?

class Test{

public static void main(String args[]){

try{

int x=-7;

System.out.println(x/2+""+(x>>1));

}catch(Exception e){

System.out.println("Exception");

}

}

}

Select all of the right answers from the flowing.

A. A compiler error

B. Exception

C. -3 -3

D. -3 -4

E. -4 -4

F. None of the above

正确答案: D

 

248. What output is produced by the following program?

class Test{

public static void main(String args[]){

try{

int x=16384;

System.out.println(x>>33);

}catch(Exception e){

System.out.println("Exception");

}

}

}

Select all of the right answers.

A. A compiler error

B. Exception

C. 0

D. 1

F. None of the above

正确答案: F

 

249. What output is produced by the following program?

class Test{

public static void main(String args[]){

try{

byte x=127;

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

System.out.println(y);

}catch(Exception e){

System.out.println("Exception");

}

}

}

Select all of the right answers from the flowing.

A. A compiler error

B. Exception

C. 0

D. 1

E. -1

F. None of the above

正确答案: C

 

401. What will happen when you attempt to compile and run this code?

class Test{

public static void main(String argv[]){

}

public static native void amethod();

}

Select the one right answer.

A. Error at compilation: native method cannot be static

B. Error at compilation native method must return value

C. Compilation but error at run time unless you have made code containing native amethod available

D. Compilation and execution without error

正确答案: D

 

402. What will happen when you attempt to compile and run the following code?

public class Test{

public static void main(String argv[]){

Test h =new Test();

}

protected Test(){

for(int i=0;i<10;i++){

System.out.prinln(i);

}

}

}

Select the one right answer.

A. Compilation error: Constructors cannot be declared protected

B. Run time error: Constructors cannot be declared protected

C. Compilation and running with output 0 to 10

D. Compilation and running with output 0 to 9

正确答案: D

 

403. What will happen when you attempt to compile and run the following code with the command line "hello there"?

public class Test{

String[] MyArg:

public static void main(String argv[]){

MyArg=argv;

}

public void amethod(){

System.out.println(argv[1]);

}

}

Select the one right answer.

A. Compile time error

B. Compilation and output of "hello"

C. Compilation and output of "there

D. None of the above

正确答案: A

 

404. What will happen when you attempt to compile and run this code?

import java.awt event.*;

import java.awt.*;

public class Test extends Frame implements WindowListener{

public void WindowClosing(WindowEvent e){

System.exit(0);

}

public void Test(){

setSize(300,300);

setVisible(true);

}

}

Select the one right answer.

A. Error at compile time.

B. Visible Frame created that that can be closed.

C. Compilation but no output at run time.

D. Error at compile time because of comment before import statements.

正确答案: A

 

405. Which of the following statements are true?

A. If a class has any abstract methods it must be declared abstract itself.

B. All methods in an abstract class must be declared as abstract.

C. When applied to a class, the final modifier means it cannot be sub-classed.

D. transient and volatile are Java modefiers.

正确答案: A、C、D

 

406. Which of the following are valid methods?

A. publie static native void amethod(){}

B. public static void amethod(){}

C. private protected void amethod(){}

D. static native void amethod();

正确答案: B、D

 

407. Which of the following statements are true?

A. static methods do mot have access to the implicit variable called this.

B. A static method may be called without creating an instance of its class.

C. A static method may not be overridden to be non-static.

D. A static method may not be overloaded.

正确答案: A、B、C

 

408. Which of the following statements are true about a variable created with the static modifier?

A. Once assigned the value of a static variable may not be altered.

B. A static variable created in a method will keep the same value between calls.

C. Only one instance of a static variable will exist for any amount of class instances.

D. The static modifier can only be applied to a primitive value.

正确答案: C

 

409.What will happen when you attempt to compile and run the following code?

import jana.io.*;

class Test{

abstract public void martley(){

}

}

public class MyEx extends Test{

public static noid main(String argv[]){

DatalnputStream fi=new DatalnputStream(Stream.in);

try{

fi.readChar();

}eatch(IOException e){

System.exit(0);

}

finally{

System.out.println("Dokng finally");}

}

}

}

Select the one right answer.

A. Compile time error.

B. It will run,wait for a key press and then exit.

C. It will run,wait for a keypress,print"Doing finally"then exit.

D. At run and immediately exit.

正确答案: A

 

410. Given the following code:

class Test {

static int oak=99;

}

public class Doverdate extends Test{

public static void main(String argv[]){

Doverdale d=new Doverdale();

d.amethod();

}

public void amethod(){

//Here

}

}

Which of the following if placed after the comment//Here, will compile and modify the value of the variable oak?

A. super.oad=1;

B. oak=33;

C. Test.oak=22;

D. oak=50.1;

Select the one right answer.

A. Error at compile time.

B. Visible Frame created that that can be closed.

C. Compilation but no output at run time.

D. Error at compile time because of comment before import statements.

正确答案: A、B、C

 

476. Which of the following statements are legal?

A. long 1=4990;

B. int i=4L;

C. float f=1.1;

D. double d=34.4;

E. double t=0.9F

正确答案: A、D、E

 

477. The variable "result" is boolean. Which expressions are legal?

A. result=true;

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

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

D. result=1

正确答案: A、B

 

478. Class Teacher and Student are subclass of class Person.

Person p;

Teacher t;

Student s;

p,t and s are all non-null.

if(t instanceof Person){s=(Student)t;}

What is the result of this sentence?

A. It will construct a Student object.

B. The expression is legal.

C. It is illegal at compilation.

D. It is legal at compilation but possible illegal at runtime.

正确答案: C

 

479. What will happen if you compile/run the following code?

1: class Test

2: {

3: static void show()

4: {

5: System.out.println("Show method in Test class");

6: }

7: }

8:

9: public class Q2 extends Test

10:{

11:static void show()

12:{

13:System.out.println("Show method in Q2 class");

14:}

15:public static void main(String[]args)

16:{

17:Test t=new Test();

18:t.show();

19:Q2 q=new Q2();

20:q.show();

21:

22:t=q;

23:t.show();

24:

25:q=t;

26:q.show();

27:}

28:}

A. prints "Show method in Test class"

"Show method in Q2 class"

"Show method in Q2 class"

"Show method in Q2 class"

B. prints "Show method in Test class"

"Show method in Q2 class"

"Show method in Test class"

"Show method in Test class"

C. prints "Show method in Test class"

"Show method in Q2 class"

"Show method in Test class"

"Show method in Q2 class"

D. Compilation error.

正确答案: D

 

480. What will happen when you invoke the following method?

1: void infiniteLoop()

2: {

3: byte b=1;

4:

5: while(++b>0);

6: System.out.println("Welcome to Java");

7: }

Select the one right answer.

A. The loop never ends(infiniteLoop).

B. Prints "Welcome to Java".

C. Compilation error at line 5. ++ operator should not be used for byte type variables.

D. Prints nothing.

正确答案: B

 

481. What is the output for the following lines of code?

1: System.out.println(" "+2+3);

2: System.out.println(2+3);

3: System.out.println(2+3+" ");

4: System.out.println(2+" "+3);

Select the one right answer.

A. Compilation error at line 3

B. Prints 23,5,5 and 23.

C. Prints 5,5,5 and 23.

D. Prints 23,5,23 and 23.

正确答案: B

 

482. Consider the following class:

classTest(int i){

void test(int i){

System.out.println("I am an int.");

}

void test(String s){

System.out.println("I am an int.");

}

public static void main(String s[]){

Test t=new Test();

char ch='y';

t.test(ch);

}

}

Which of the statements below is true? (Choose one)

A. Line 5 will not compile, because void methods cannot be overridden.

B. Line 12 will not compile, because there is no version of test() that rakes a char argument.

C. The code will compile and will throw an exception at line 12.

D. The code will compile and produce the following output: I am an int.

E. The code will compile and produce the following output: I am a String.

正确答案: D

 

483. Which of the following do not lead to a runtime error?

Select all correct answers.

A. "john"+"was"+"here"

B. "john"+3

C. 3+5

D. 5+5.5

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

 

484. What is the output when following code is run?

1. class OuterOne{

2. class InnerOne extends OuterOne{}

3. static void thisMethod(){

4. Object o=(Object)new OuterOne();

5. OuterOne foo=(OuterOne)o;

6. }

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

8. thisMethod();

9. }

10.}

Select the one right answer.

A. Will compile fine, but at runtime a ClassCastException is thrown

B. Will compile and run fine

C. Compiler error at line 4

D. Compiler error at line 5

正确答案: B

 

485. Given the following code:

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

2. byte b=12;

3. byte c=126;

4. byte d=b-c;

5. System.out.println(d);

6. }

Select the one right answer.

A. Compilation succeeds and prints 1.

B. Compilation succeeds but there will a Runtime Exception.

C. Compilation error at line no 4.

D. Compilation error at line no 5.

正确答案: C

 

486. Given the following code:

Class Test{

public static void main(String args[]){

float[][]f1={{1.2f,2.3f},{4.5f,5.6f}}

Object oo=f1;

f1[1][1]=oo;

System.out.println("Best Wishes"+f1[1][1]);

}

}

What will the output?

A. {4.5,5.6}

B. 4.5

C. compilation error in line no.5

D. exception

正确答案: C

 

551. What is the value of j when printed?

class Test{

public static void main(String args[]){

long x=4, j=0;

switch(x){

case 1:j++;

case 2:j++;

case 3:j++;

case 4:j++;

case 5:j++;

break;

default:j++;

}

System.out.println(j);

}

}

Select the one right answer.

A. 1

B. Compiler error

C. 6

D. 3

E. 2

正确答案:B

 

552. Given the following code:

import java.io*;

class Test{

static void method() throws Exception{

throw new EOFException();

}

public static voidmain(String args[]){

try{

method();

}catch(////){

}

}

}

Which of the following should be placed at //// so that the code will compile without errors?

A. IOExeption e

B. EOFExceotion e

C. MalformedURLException e

D. NullPointerException e

E. Exception e

F. FileNotFoundException

正确答案:E

 

553. Given the following code:

switch(s){

default: System.out.println("Best Wishes");

}

Which datatype can 's' be?

A. byte

B. long

C. float

D. double

正确答案:A

 

554. Given the following code:

public static void main(String args[]){

int i=1;

int j=10;

do{

if(i>j)

continue;

j--;

} while(++i<6);

System.out.println("i="+i+"j="+j);

}

What will be the output?

A. i=4,j=5

B. i=5,j=6

C. i=5,j=5

D. i=4,j=6

E. i=6,j=5

正确答案:E

 

555. What is the output?

class Test{

public static void main(String args[]){

default;

for(int i=0; i<10; i++){

mid:

for(int j=0;j<5;j++){

System.out.println(j);

}

}

}

}

Select the one right answer.

A. runtime exeption

B. print 0--4

C. compilation error

正确答案:C

 

556. Given the following code:

1. class Test{

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

3. int x=4;

4. int y=2;

5. if(x/y){

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

7. }

8. }

9. }

What is the output?

A. prints 6

B. compilation error at line no.6

C. compilation error at line no.5

D. runtime exception occurs

E. prints 4

正确答案:C

 

557. Given the following code:

switch(x){

case 1:System.out.println("case 1");

case 2:

case 3:System.out.println("case 2");}

break;

default:System.out.println("case 3");}

For what values of x will the output include case 3.

A. 1

B. 2

C. 3

D. 4

正确答案:D

 

558. Given the following code:

if(x>4){

System.out.println("case 1");

}

else

if(x>9){

System.out.println("case 2");

}

else

System.out.println("case 3");

}

What value(s)of x will cause case 3 printed in the output?

A. less than zero.

B. less than 4

C. between 4 and 9

D. 10 and greater

E. none

正确答案:B

 

559. Given the following code:

try{

method();

some code1

}

catch(IOException a){

some code2

}

finally{

some code3

}

some code4

What will be excecuted if the method throws NullPointerException?

A. some code2 run

B. some code3 run

C. some code3 and some code4

D. Compilation Error

正确答案:C

 

560. Given the following code:

1. //

2. if(method()){

3. //}

4. else{

5. //

6. }

7. //

Which line you insert the throw mew Exception if the code should throw the exception only if the method() returns true?

A. 2

B. 3

C. 4

D. 5

正确答案:B

671. Given the following code:

        class Super{

           int i=0

           Super(String s){

               i=10

            }

}

class Sub extends Super{

   Sub(String s){

       i=20;

   }

  public static void main(String args[]){

      Sub b=new Sub("hello");

      System.out.printIn(i);

What will be the value of i?

A. Compilation Error

B. Runtime Error

C.0

D.10

E.20

正确答案:E

 

672. Where will be a 'is a' relationship will occur select one?

 

A. interface Person

   class Employee implements Person

B. interface Shape

   interface Rectangle extends Shape

C. interface Component

   class Objects implement Component{

   Component[] Component;

   }

正确答案: B

 

673.which are the correct forms of Constructors for the class hai?

A. public void hai(int a)

B. hai(int a,int b)

C. public hai(int a)

D. int hai(int c, int d)

E. int hai()

F. int hai(String s)

正确答案: B C

 

674. Which are the orrect forms of overriding for the method void hai(int a,int b)?

A.public void hai(int a,int b)

B.protected void hai(int a,int b)

C.public hai(int a)

D.int hai(int c,int d)

E.int Hai()

f.int hai(String s)

正确答案: A B

 

675. Given the following code:

      1.interface foo

      2.{

      3.int I=0;

      4.}

      5.class sreejith implements foo

      6.{

      7.public static void main(String args[])

      8.{sreejith s=new sreejith();

      9.int j=0;

      10.j=s.I;

      11.j=sreejith.I;

      12.j=foo.i;

      13.s.I=2;

}

}

 

where will compilation fail?

 

A.10

B.11

C.12

D.13

E. No error

正确答案:D

 

676.What is the modifier is used to make a method to be overridden in subclass?

A. final

B. abstract

C. static

D. volatile

正确答案:B

 

677. Giventhe following code:

      public class Outer{

        //////

      }

What should be inserted at ///// so that the code will compile fine?

 A. private class Inner{

       static int k;

   }

 B. static class Inner{

        static int k;

    }

 C. public class Inner{

     static int k;

   }

 D. public abstract class Inner{

     public abstract void method();

   }

正确答案:B D

 

678.Which of the following are true about encapsulation?

A. Direct access to variables.

B. Access to variables through methods.

C. keeping methods protected.

D. use methods access and modify the variable data.

正确答案:B D

 

679.Given the following code:

    1.class Happy {

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

    3.public class Sad {

    4.public void methodA() {

    5.System.out.println("inside sad");

    6.}

    7.}

    8.System.out.println("inside happy");

    9.}

    10.}

What will be the output?

A. compilation error at line no.3

B. compilation error at line no.4

C. compilation error at line no.5

D. compilation succeeds but runtime exception

E. clean compile and give the output "inside happy"

正确答案: A

 

680. What is true about constructors?

A. They initialize all the member variables

B. They initialize all the instance variables

C. If there is no constructor. the compiler includes default constructor.

D. Compiler supplied constructor will invoke the default constructor of the super class.

正确答案: C D

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

抱歉!评论已关闭.