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
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
责任编辑:小草