免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3106 | 回复: 6
打印 上一主题 下一主题

SCJP综合测试题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-10-30 08:13 |只看该作者 |倒序浏览
购买了几套SCJP的测验题,共享给大家
1. Which of the following are valid definitions of an application's main( ) method?
A.   public static void main();
B.   public static void main( String args );
C. public static void main( String args[] );
D.  public static void main( Graphics g );
E. public static boolean main( String args[] );

2. If MyProg.java were compiled as an application and then run from the command line as:
              java MyProg I like tests
what would be the value of args[ 1 ] inside the main( ) method?
A.   MyProg
B.     "I"
C.  "like"
D. 3
E. 4
F. null until a value is assigned

3. Which of the following are Java keywords?
A.      array
B.     boolean
C.     Integer
D.     protect
E. super

4. After the declaration:
char[] c = new char[100];
what is the value of c[50]?
A.   50
B.  49
C.  '\u0000'
D. '\u0020'
E." "
F. cannot be determined
G. always null until a value is assigned

5. After the declaration:
int x;
the range of x is:
A.   -231 to 231-1
B.     -216 to 216 - 1
C. -232 to 232
D. -216 to 216
E. cannot be determined; it depends on the machine

6. Which identifiers are valid?
A.   _xpoints
B.    r2d2
C.    bBb$
D.    set-flow
E. thisisCrazy  
 
7. Which of the following describe the sequence of method calls that result in a component being redrawn?
A. invoke paint() directly
B. invoke update which calls paint()
C. invoke repaint() which invokes update(), which in turn invokes paint()
D. setflow

8. Which of the following statements assigns "Hello Java" to the String variable s?
A. String s = "Hello Java";
B. String s[] = "Hello Java";
C. new String s = "Hello Java";
D. String s = new String("Hello Java";

9. An integer, x has a binary value (using 1 byte) of 10011100. What is the binary value of z after these statements:
int y = 1 << 7;
int z = x & y;
A.  1000 0001
B.  1000 0000
C.  0000 0001
D. 1001 1101
E. 1001 1100

10. Which statements are accurate:
A.   >;>; performs signed shift while >;>;>; performs an unsigned shift.
B.  >;>;>; performs a signed shift while >;>; performs an unsigned shift
C.  << performs a signed shift while <<< performs an insigned shift.
D. <<< performs a signed shift while << performs an unsigned shift.

11. The statement ...
String s = "Hello" + "Java";
yields the same value for s as ...
String s = "Hello";
String s2= "Java";
s.concat( s2 );
A.   True
B.  False

论坛徽章:
0
2 [报告]
发表于 2003-10-30 08:17 |只看该作者

SCJP综合测试题

12. If you compile and execute an application with the following code in its main() method:
        String s = new String( "Computer" );
        if( s == "Computer" )
                System.out.println( "Equal A" );
        if( s.equals( "Computer" ) )
                System.out.println( "Equal B" );
A. It will not compile because the String class does not support the = = operator.
B.  It will compile and run, but nothing is printed.
C.  "Equal A" is the only thing that is printed.
D. "Equal B" is the only thing that is printed.
E.Both "Equal A" and "Equal B" are printed.

13. Consider the two statements:

        1. boolean passingScore = false && grade == 70;
        2. boolean passingScore = false & grade == 70;
The expression
grade == 70
is evaluated:
A.  in both 1 and 2
B. in neither 1 nor 2
C. in 1 but not 2
D. in 2 but not 1
E.invalid because false should be FALSE

14. Given the variable declarations below:

byte myByte;
int myInt;
long myLong;
char myChar;
float myFloat;
double myDouble;
Which one of the following assignments would need an explicit cast?
A. myInt = myByte;
B. myInt = myLong;
C. myByte = 3;
D.  myInt = myChar;
E. myFloat = myDouble;
F. myFloat = 3;
G. myDouble = 3.0;

15. Consider this class example:

class MyPoint
{  void myMethod()
   {  int x, y;
      x = 5; y = 3;
      System.out.print( " ( " + x + ", " + y + " ) " );
      switchCoords( x, y );
      System.out.print( " ( " + x + ", " + y + " ) " );
   }
   void switchCoords( int x, int y )
   {  int temp;
      temp = x;
      x = y;
      y = temp;
      System.out.print( " ( " + x + ", " + y + " ) " );
   }
}
What is printed to standard output if myMethod() is executed?
A. (5, 3) (5, 3) (5, 3)
B. (5, 3) (3, 5) (3, 5)
C. (5, 3) (3, 5) (5, 3)

16. To declare an array of 31 floating point numbers representing snowfall for each day of March in Gnome, Alaska, which declarations would be valid?
A. double snow[] = new double[31];
B. double snow[31] = new array[31];
C. double snow[31] = new array;
D. double[] snow = new double[31];

17. If arr[] contains only positive integer values, what does this function do?

public int guessWhat( int arr[] )
{  int x= 0;
   for( int i = 0; i < arr.length; i++ )
      x = x < arr ? arr : x;
   return x;
}
A.   Returns the index of the highest element in the array
B.    Returns true/false if there are any elements that repeat in the array
C.  Returns how many even numbers are in the array
D. Returns the highest element in the array
E. Returns the number of question marks in the array

18. Consider the code below:

arr[0] = new int[4];
arr[1] = new int[3];
arr[2] = new int[2];
arr[3] = new int[1];
for( int n = 0; n < 4; n++ )
System.out.println( /* what goes here? */ );

Which statement below, when inserted as the body of the for loop, would print the number of values in each row?
A.   arr[n].length();
B. arr.size;
C.  arr.size -1;
D. arr[n][size];
E. arr[n].length;

19.If size = 4, triArray looks like:

 
int[][] makeArray( int size)
{  int[][] triArray = new int[size] [];
   int val=1;
   for( int i = 0; i < triArray.length; i++ )
   {  triArray = new int[i+1];
          for( int j=0; j < triArray.length; j++ )
      {  triArray[j] = val++;
      }
   }
   return triArray;
}
A.  
1 2 3 4
5 6 7
8 9
10
B.  1 4 9 16
C.  1 2 3 4
D.
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
E.
1
2 3
4 5 6
7 8 9 10

20. Which of the following are legal declarations of a two-dimensional array of integers?
A.   int[5][5]a = new int[][];
B.     int a = new int[5,5];
C.  int[]a[] = new int[5][5];
D. int[][]a = new[5]int[5];

21. Which of the following are correct methods for initializing the array "dayhigh" with 7 values?
A.   int dayhigh = { 24, 23, 24, 25, 25, 23, 21 };
B.int dayhigh[] = { 24, 23, 24, 25, 25, 23, 21 };
C.  int[] dayhigh = { 24, 23, 24, 25, 25, 23, 21 };
D. int dayhigh [] = new int[24, 23, 24, 25, 25, 23, 21];
E. int dayhigh = new[24, 23, 24, 25, 25, 23, 21];

22. Choose all valid forms of the argument list for the FileOutputStream constructor shown below:
A. FileOutputStream( FileDescriptor fd )
B. FileOutputStream( String n, boolean a )
C. FileOutputStream( boolean a )
D.  FileOutputStream()
E. FileOutputStream( File f )

论坛徽章:
0
3 [报告]
发表于 2003-10-30 08:21 |只看该作者

SCJP综合测试题

23.A "mode" argument such as "r" or "rw" is required in the constructor for the class(es):
A.   public static boolean main( String args[] );
B. InputStream
C.  RandomAccessFile
D. File
E. None of the above

24. Consider the code below:

public static void main( String args[] )
{  int a = 5;
   System.out.println( cube( a ) );
}
int cube( int theNum )
{
   return theNum * theNum * theNum;
}
What will happen when you attempt to compile and run this code?
A. It will not compile because cube is already defined in the java.lang.Math class.
B.It will not compile because cube is not static.
C.It will compile, but throw an arithmetic exception.
D.It will run perfectly and print "125" to standard output.

25. Given the variables defined below:
int one = 1;
int two = 2;
char initial = '2';
boolean flag = true;

Which of the following are valid?
A. if( one ){}
B.if( one = two ){}
C. if( one == two ){}
D.if( flag ){}
E. switch( one ){}
F. switch( flag ){}
G.switch( initial ){} 

26. If val = 1 in the code below:

 
switch( val )
{  case 1: System.out.print( "" );
   case 2:
   case 3: System.out.print( "Q" );
      break;
   case 4: System.out.print( "R" );
   default: System.out.print( "S" );
}
Which values would be printed?
A.  P
B. Q
C. R
D. S

27. Assume that val has been defined as an int for the code below:

 
if( val >; 4 )
{  System.out.println( "Test A" );
}
else if( val >; 9 )
{  System.out.println( "Test B" );
}
else System.out.println( "Test C" );
Which values of val will result in "Test C" being printed:
A.  val < 0
B. val between 0 and 4
C. val between 4 and 9
D. val >; 9
E. val = 0
F. no values for val will be satisfactory

28. Which of the following are valid definitions of an application's main( ) method?
A.   public static void main();
B.   public static void main( String args );
C. public static void main( String args[] );
D.  public static void main( Graphics g );
E. public static boolean main( String args[] );

29. For the code:

m = 0;
while( m++ < 2 )
   System.out.println( m );
Which of the following are printed to standard output?
A.  0
B. 1
C. 2
D. 3
E. Nothing and an exception is

30. Consider the code fragment below:

 
outer: for( int i = 1; i <3; i++ )
   {  inner: for( j = 1; j < 3; j++ )
      {  if( j==2 )
            continue outer;
            System.out.println( "i = " +i ", j = " + j );
      }
   }       
Which of the following would be printed to standard output?
A.  i = 1, j = 1
B. i = 1, j = 2
C. i = 1, j = 3
D. i = 2, j = 1
E. i = 2, j = 2
F. i = 2, j = 3
G. i = 3, j = 1
H. i = 3, j = 2

31. Consider the code below:

void myMethod()
{  try
   {  
      fragile();
   }
   catch( NullPointerException npex )
   {  
      System.out.println( "NullPointerException thrown " );
   }
   catch( Exception ex )
      {  
         System.out.println( "Exception thrown " );
      }
   finally
   {  
      System.out.println( "Done with exceptions " );
   }
   System.out.println( "myMethod is done" );
}
What is printed to standard output if fragile() throws an IllegalArgumentException?
A.  "NullPointerException thrown"
B. "Exception thrown"
C. "Done with exceptions"
D. "myMethod is done"
E. Nothing is printed

32. Consider the following code sample:

class Tree{}
class Pine extends Tree{}
class Oak extends Tree{}
public class Forest
{  public static void main( String[] args )
   {  Tree tree = new Pine();

      if( tree instanceof Pine )
      System.out.println( "ine" );

      if( tree instanceof Tree )
      System.out.println( "Tree" );

      if( tree instanceof Oak )
      System.out.println( "Oak" );

      else System.out.println( "Oops" );
   }
}

Select all choices that will be printed:
A.  Pine
B. Tree
C. Forest
D. Oops
E. (nothing printed)

33. Consider the classes defined below:

import java.io.*;
class Super
{
        int methodOne( int a, long b ) throws IOException
        { // code that performs some calculations
    }
        float methodTwo( char a, int b )
        { // code that performs other calculations
    }
}
public class Sub extends Super
{

}
Which of the following are legal method declarations to add to the class Sub? Assume that each method is the only one being added.
A.  public static void main( String args[] ){}
B. float methodTwo(){}
C. long methodOne( int c, long d ){}
D. int methodOne( int c, long d ) throws ArithmeticException{}
E. int methodOne( int c, long d ) throws FileNotFoundException{}
 

论坛徽章:
0
4 [报告]
发表于 2003-10-30 08:28 |只看该作者

SCJP综合测试题

34. Assume that Sub1 and Sub2 are both subclasses of class Super.

Given the declarations:

Super super = new Super();
Sub1 sub1 = new Sub1();
Sub2 sub2 = new Sub2();

Which statement best describes the result of attempting to compile and execute the following statement:

super = sub1;
A.   Compiles and definitely legal at runtime
B.  Does not compile
C.  Compiles and may be illegal at runtime

35. For the following code:

class Super
{  int index = 5;
   public void printVal()
      {  System.out.println( "Super" );
      }
}
class Sub extends Super
{  int index = 2;
   public void printVal()
   {  System.out.println( "Sub" );
   }
}
public class Runner
{  public static void main( String argv[] )
   {  Super sup = new Sub();
      System.out.print( sup.index + "," );
      sup.printVal();
   }
}
What will be printed to standard output?
A.  The code will not compile.
B. The code compiles and "5, Super" is printed to standard output.
C. The code compiles and "5, Sub" is printed to standard output.
D. The code compiles and "2, Super" is printed to standard output.
E.The code compiles and "2, Sub" is printed to standard output.
F.The code compiles, but throws an exception.  

36. How many objects are eligible for garbage collection once execution has reached the line labeled Line A?

String name;
String newName = "Nick";
newName = "Jason";
name = "Frieda";

String newestName = name;

name = null;
//Line A
A.   0
B. 1
C. 2
D. 3
E. 4

37. Which of the following statements about Java's garbage collection are true?
A. The garbage collector can be invoked explicitly using a Runtime object.
B. float methodTwo(){}
C. long methodOne( int c, long d ){}
D. int methodOne( int c, long d ) throws ArithmeticException{}

38.A directory can be created using a method from the class(es):
A.   public static boolean main( String args[] );  
B.  DataOutput
C. Directory
D. FileDescriptor
E. FileOutputStream

39. Which methods are required to implement the interface Runnable.
A.   None of these
B.  run()
C.  stop()
D. update()
E. resume()

40. If raf is a RandomAccessFile, what is the result of compiling and executing the following code?

raf.seek( raf.length() );
A.   The code will not compile.
B. An IOException will be thrown.
C. The file pointer will be positioned immediately before the last character of the file.
D.  The file pointer will be positioned immediately after the last character of the file.

41. For what reasons might a thread stop execution?
A.  A thread with higher priority began execution.
B. The thread's wait() method was invoked.
C. long methodOne( int c, long d ){}
D. The thread's pause() method was invoked.
E. methodOne( int c, long d ) throws FileNotFoundException{}

42. Which method below can change a String objects ?
A.   equals( s )
B.  substring( s )
C.  concat( s )
D. toUpperCase( s )
E.  none of the above will change s

43. If s1 is declared as:

String s1 = "phenobarbital";

What will be the value of s2 after the following line of code:

String s2 = s1.substring( 3, 5 );
A.  null
B."eno"
C. "enoba"
D. "no"

44. What method(s) from the java.lang.Math class might method() be if the statement

method( -4.4 ) == -4;

is true.
A. round()
B. min()
C. trunc()
D. abs()
E. floor()
F. ceil()

论坛徽章:
0
5 [报告]
发表于 2003-10-30 08:31 |只看该作者

SCJP综合测试题

45. Which methods does java.lang.Math include for trigonometric computations?
A. sin()
B. cos()
C. tan()
D. aSin()
E. aCos()
F. aTan()
G. toDegree()

46. This piece of code:

TextArea ta = new TextArea( 10, 3 );

Produces (select all correct statements):
A. a TextArea with 10 rows and up to 3 columns
B.a TextArea with a variable number of columns not less than 10 and 3 rows
C. a TextArea that may not contain more than 30 characters
D.a TextArea that can be edited

47. In the list below, which subclass(es) of Component cannot be directly instantiated:
A.   Panel
B.     Dialog
C.  Container
D. Frame  

48. Of the five Component methods listed below, only one is also a method of the class MenuItem. Which one?
A.   setVisible( boolean b )
B. setEnabled( boolean b )
C. getSize()
D. setForeground( Color c )
E. setBackground( Color c )

49. If a font with variable width is used to construct the string text for a column, the initial size of the column is:
A.   determined by the number of characters in the string, multiplied by the width of a character in this font
B.  determined by the number of characters in the string, multiplied by the average width of a character in this font
C.  exclusively determined by the number of characters in the string
D. undetermined

50. Which of the following methods from the java.awt.Graphics class would be used to draw the outline of a rectangle with a single method call?
A. thisisCrazy
B. drawRect()
C. fillPolygon()
D. drawPolygon()
E. drawLine()

51. The Container methods add( Component comp ) and add( String name, Component comp ) will throw an IllegalArgumentException if comp is a:
A. button
B. list
C. window
D. textarea
E. container that contains this container

52. Of the following AWT classes, which one(s) are responsible for implementing the components layout?

A. LayoutManager
B.  GridBagLayout
C. ActionListener
D. WindowAdapter
E. FlowLayout

53. A component that should resize vertically but not horizontally should be placed in a:
A.   BorderLayout in the North or South location
B. FlowLayout as the first component
C.BorderLayout in the East or West location
D. BorderLayout in the Center location
E.GridLayout

54.Which of the following methods is used to change the contents of the string World to also include the characters Hello?
A.   trim ()
B.     insert ()
C.  append ()
D. None of these

55.Which of the following methods is used to change the contents of the string World to also include the characters Hello?
A.   trim ()
B.     insert ()
C.  append ()
D. None of these         【完毕】

论坛徽章:
0
6 [报告]
发表于 2003-10-30 10:43 |只看该作者

SCJP综合测试题

有答案吗

论坛徽章:
0
7 [报告]
发表于 2003-10-30 11:55 |只看该作者

SCJP综合测试题

有,不过我希望大家都先认真考虑一下

经过考虑的答案才有意义
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP