格林模拟试题一参考答案
百度广告
5) int i=10;
explanation:
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
4) while
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
4) _3_
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 initializedtype 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.
answer 11)3) error mine must be declared abstract
a class that contains an abstract method must itself be declared as abstract. it may however contain non abstract methods. any class derived from an abstract class must either define all of the abstract methods or be declared abstract itself.
answer 12)3) one, two, default
code will continue to fall through a case statement until it encounters a break.
answer 13)2) default, zero
although it is normally placed last the default statement does not have to be the last item as you fall through the case block. because there is no case label found matching the expression the default label is executed and the code continues to fall through until it encounters a break.
answer 14)2,3
example 1 will not compile because if must always test a boolean. this can catch out c/c++ programmers who expect the test to be for either 0 or not 0.
||| answer 15)3) no such file found, doing finally, -1
the no such file found message is to be expected, however you can get caught out if you are not aware that the finally clause is almost always executed, even if there is a return statement.
answer 16)1) methods cannot be overriden to be more private
static methods cannot be overriden but they can be overloaded. if you have doubts about that statement, please follow and read carefully the link given to the sun tutorial below. there is no logic or reason why private methods should not be overloaded. option 4 is a jumbled up version of the limitations of exceptions for overriden methods
answer 17)3) runtime exception
without the cast to sub you would get a compile time error. the cast tells the compiler that you really mean to do this and the actual type of b does not get resolved until runtime. casting down the object hierarchy is a problem, as the compiler cannot be sure what has been implemented in descendent classes. casting up is not a problem because sub classes will have the features of the base classes. this can feel counter intuitive if you are aware that with primitives casting is allowed for widening operations (ie byte to int).
answer 18)1) system.out.println( -1 >>> 2);will output a result larger than 10
>> 2); will output a positive number
> 1); will output the number 1
you can test this with the following classm
public class shift{public static void main(string argv){
>> 2);
>> 2);
> 1);
}
java does not have a
编辑推荐:
温馨提示:因考试政策、内容不断变化与调整,长理培训网站提供的以上信息仅供参考,如有异议,请考生以权威部门公布的内容为准! (责任编辑:长理培训)
-
国家电网30270试题
-
湖南中烟7463试题
-
湖南统招专升本不连网,流畅做题
-
长沙理工大学考研培训4532试题
已有 22658 名学员学习以下课程通过考试
精品课程
更多- 电网书籍
- 财会书籍
- 其它工学书籍
- 电气拼团课程
- 财会拼团课程
- 其它工学拼团
-
- 长理培训微信公众号
- 每日推送精彩考试资讯
长按二维码识别
微信搜索“ 长理培训”
-
- 加入QQ群一起来考国网!
- QQ群号:223940140
点击进入
长理培训客户端 资讯,试题,视频一手掌握
去 App Store 免费下载 iOS 客户端
点击加载更多评论>>