SCJP模拟试题:SCJPMockExam(4)答案
来源:优易学  2011-11-28 16:51:08   【优易学:中国教育考试门户网】   资料下载   IT书店

Answers

--------------------------------------------------------------------------------

Answer 1)
Back to question 1) 
Objective 4.5)

5) int i=10; 

explanation: 
1) float f=1.3; 
Will not compile because the default type of a number with a floating point component is a double. This would compile with a cast as in 

float f=(float) 1.3 


2) char c="a"; 

Will not compile because a char (16 bit unsigned integer) must be defined with single quotes. This would compile if it were in the form 

char c=’a’; 

3) byte b=257; 

Will not compile because a byte is eight bits. Take of one bit for the sign component you can define numbers between 

-128 to +127 

4) a boolean value can either be true or false, null is not allowed

--------------------------------------------------------------------------------

Answer 2)
Back to question 2) 

Objective 4.1 

1) Can’t make static reference to void amethod. 

Because main is defined as static you need to create an instance of the class in order to call any non-static methods. Thus a typical way to do this would be. 


MyClass m=new MyClass(); 

m.amethod(); 


Answer 2 is an attempt to confuse because the convention is for a main method to be in the form 

String argv[] 

That argv is just a convention and any acceptable identifier for a string array can be used. Answers 3 and 4 are just nonsense.

 

Answer 3)
back to Question 3) 
Objective 4.1)

2 and 3 will compile without error. 

1 will not compile because any package declaration must come before any other code. Comments may appear anywhere

--------------------------------------------------------------------------------

Answer 4)
Back to question 4) 
Objective 4.5) 

1) A byte is a signed 8 bit integer. 

--------------------------------------------------------------------------------

Answer 5)
Back to question 5) 
Objective 4.2) 

4) Exception raised: "java.lang.ArrayIndexOutOfBoundsException: 2" 

Unlike C/C++ java does not start the parameter count with the program name. It does however start from zero. So in this case zero starts with good, morning would be 1 and there is no parameter 2 so an exception is raised. 

--------------------------------------------------------------------------------

Answer 6)
Back to question 6) 
Objective 4.3) 

1) if 
3) goto 
4) while 
5) case 

then is not a Java keyword, though if you are from a VB background you might think it was. Goto is a reserved word in Java. 

--------------------------------------------------------------------------------

Answer 7)
Back to Question 7) 
Objective 4.1) 

2) variable2 
3) _whatavariable 
4) _3_ 
5) $anothervar 

An identifier can begin with a letter (most common) or a dollar sign($) or an underscore(_). An identifier cannot start with anything else such as a number, a hash, # or a dash -. An identifier cannot have a dash in its body, but it may have an underscore _. Choice 4) _3_ looks strange but it is an acceptable, if unwise form for an identifier. 

--------------------------------------------------------------------------------

Answer 8)
Back to Question 8) 
Objective 4.4) 

4) 0 

Class level variables are always initialised to default values. In the case of an int this will be 0. Method level variables are not given default values and if you attempt to use one before it has been initialised it will cause the 

Error Variable i may not have been initialized
type of error.

--------------------------------------------------------------------------------

Answer 9)
Back to Question 9) 
Objective 4.4) 

3 ) 2 

No error will be triggered. 

Like in C/C++, arrays are always referenced from 0. Java allows an array to be populated at creation time. The size of array is taken from the number of initializers. If you put a size within any of the square brackets you will get an error. 

--------------------------------------------------------------------------------

Answer 10)
Back to question 10) 
Objective 4.4) 

3) 0 

Arrays are always initialised when they are created. As this is an array of ints it will be initalised with zeros. 

--------------------------------------------------------------------------------

[1] [2] [3] [4] [5] [6] 下一页

责任编辑:小草

文章搜索:
 相关文章
热点资讯
热门课程培训