JAVA认证格林模拟试题一答案及解析
来源:优易学  2011-11-28 15:35:05   【优易学:中国教育考试门户网】   资料下载   IT书店

answer 1)

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)

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)

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)

1) a byte is a signed 8 bit integer.


answer 5)

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)

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)

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)

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)

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)

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] 下一页

责任编辑:小草

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