无忧首页企业系统我的无忧
无忧服务:
兼职活动培训
娱乐交友:
交友社区资讯
全职实习:
实习暑假寒假
微信号:school51
扫一下,立即关注
加关注
在线支付,立省10元
下载新版APP
===大学生成长生活平台===

格林模拟试题三参考答案(1)

2012-12-26来源/作者:卫凯点击次数:613

 

answers

answer to question 1)

1) float f=1/3;
2) int i=1/3;
4) double d=999d;

the fact that option 3 does not compile may be a surprise. the problem is because the default type for a number with a decimal component is a double and not a float. the additional trailing d in the option with 999 doesn't help, but it doesn't harm.


answer to question 2)

2) new

the option null (note the upper case letter) is definitely not a keyword. there is some discussion as to i. there is some discussion as to if null is a keyword but for the purpose of the exam you should probably assume it is a keyword.

the option instanceof is a bit of a misleading option that would probably not occur on the exam. the real keyword is instanceof (note that the of has no capital letter o). i had the incorrect version in an earlier version of this tutorial as it looks more likely to my eyes. the instanceof keyword looks like a method, but it is actually an operator.

the option wend is probably valid in some other language to indicate the end of a while loop, but java has no such keyword.


answer to question 3)

1) system.out.println(1+1);
2) int i=2+'2';
option 3 is not valid because single quotes are used to indicate a character constant and not a string. several people have emailed me to say that option 3 will compile. when they eventually compiled the exact code they have agreed, it will not compile. let me re-state that

string s="on"+'one';

will not compile.

option 4 will not compile because 255 is out of the range of a byte


answer to question 4)

1) the garbage collection algorithm in java is vendor implemented

threading and garbage collection are two of the few areas that are platform dependent. this is one of the
reasons why java is not suitable for realtime programming. it is not a good idea use it to control your
plane or nuclear power station. once an instance of the integer class has a value it cannot be changed.


answer to question 5)

(not on the official sub objectives but this topic does come up on the exam)

2) the randomaccessfile class allows you to move directly to any point a file.
4) the characteristics of an instance of the file class such as the directory separator, depend on the current underlying operating system

the file class can be considered to represent information about a file rather than a real file object. you can create a file in the underlying operating system by passing an instance of a file to a stream such as fileoutputstream. the file will be created when you call the close method of the stream.

answer to question 6)

2) the instanceof operator can be used to determine if a reference is an instance of a particular primitive wrapper classthe instanceof operator can only be used to make a static comparison with a class type. java1.1 added the isinstance method to the class class to allow you to dynamically determine a class type. the exam does not test you on isinstance.


answer to question 7)

2) interfaces cannot have constructors

if you try to create a constructor for an interface the compiler will give you an error message something like

"interface can't have constructors".

4) interfaces are the java approach to addressing the single inheritance model, but require implementing classes to create the functionality of the interfaces.

an interface may contain variables as well as methods. however any variables are final by default and must be assigned values on creation. a class can only extend one other class (single inheritance) but may implement as many interfaces as you like (or is sensible).


answer to question 8)

none of these are valid statements. the math class is final and cannot be extended. the max method takes two parameters, round only takes one parameter and there is no mod parameter. you may get questions in the exam that have no apparently correct answer. if you are absolutely sure this is the case, do not check any of the options.


answer to question 9)

1) the runnable interface has only one method run that needs to be created in any class that implements it. the start method is used to actually call and start the run method executing.


answer to question 10)

1) a byte can represent between -128 to 127

the char type is the only unsigned type in java and thus cannot represent a negative number.

for more information on this topic go to


answer to question 11)

2) compilation and no output at runtime

because the method in base called base has a return type it is not a constructor and there for does not get called on creation of an instance of its child class in

for more information on this topic go to

answer to question 12)

4) compilation and output of hello

this type of question is particularly calculated to catch out c/c++ programmers who might expect parameter zero to be the name of the compiler.

for more information on this topic go to

answer to question 13)

1) if a class has any abstract methods it must be declared abstract itself.
3) the final modifier means that a class cannot be sub-classed
4) transient and volatile are java modifiers

an abstract class may have non abstract methods. any class that descends from an abstract class must implement the abstract methods of the base class or declare them as abstract itself.

for more information on this topic go to


answer to question 14)

2) public static void amethod(){}
4) static native void amethod();,4mr*3\g1c/1lQ[本资料来源于贵州学习网 http://www.gzu521.com],4mr*3\g1c/1lQ

option 1 is not valid because it has braces and the native modifier means that the method can have no body. this is because the body must be implemented in some other language (often c/c++). option 3 is not valid because private and protected contradict themselves.

for more information on this topic go to


answer to question 15)

4) constructors are not inherited

constructors can be marked public, private or protected. constructors do not have a return type.

for more information on this topic go to

 





相关阅读



关于我们 | 联系我们 | 用户指南 | 网站地图 | 意见建议 | 会员注册 | 用户协议 | 隐私政策