格林模拟试题三参考答案(3)
answer to question 27)
2) output of "hello crowle"
this code is an example of a short circuited operator. because the first operand of the || (or) operator returns true java sees no reason to evaluate the second. whatever the value of the second the overall result will always be true. thus the method called place is never called.
answer to question 28)
4) none of the above;
you may access methods of a direct parent class through the use of super but classes further up the hierarchy are not visible
answer to question 29)
2) a method with the same name completly replaces the functionality of a method earlier in the hierarchy
option 3 is more like a description of overloading. i like to remind myself of the difference between overloading and overriding in that an overriden method is like something overriden in the road, it is squashed, flat no longer used and replaced by something else. an overloaded method has been given extra work to do (it is loaded up with work), but it is still being used in its original format. this is just my little mind trick and doesn't match to anything that java is doing.
answer to question 30)
2) the / operator is used to divide one value by another
3) the # symbol may not be used as the first character of a variable
the % is the modulo operator and returns the remainder after a division. thus 10 % 3=1
the $ symbol may be used as the first character of a variable, but i would suggest that it is generally not a good idea. the # symbol cannot be used anywhere in the name of a variable. knowing if a variable can start with the # or $ characters may seem like arbitrary and non essential knowlege but questions like this do come up on the exam.
answer to question 31)
1) the default layout manager for an applet is flowlayout
4) the flowlayout manager attempts to honor the preferred size of any components
the default layout manager fror an application is borderlayout. an applet will use the default of flowlayout if one is not specifically applied
answer to question 32)
3) only one instance of a static variable will exist for any amount of class instances
option 1) is more a description of a final variable. option 2 is designed to fool visual basic programmers like me as this is how you can use the keyword static in vb. the modifier static can be applied to a class (only an innner class) , method or variable.
answer to question 33)
1) java uses a system called utf for i/o to support international character sets
3) an instance of fileinputstream may not be chained to an instance of fileoutputstream
4) file i/o activities requires use of exception handling
internally java uses unicode which are 16 bit characters. for i/o java uses utf which may be more thatn 16 bits per chamore thatn 16 bits per character.
generally inputstreams can only be chained to other inputstreams and outputstreams can only be chained to other outputstreams. the piped streams are an exception to this.
answer to question 34)
1) compile time error
it wil produce an error like "abstract and native method can't have a body. this is typical of the more misleading question where you might think it is asking you about the circumstances under which the finally clause runs, but actually it is about something else.
answer to question 35)
2) compilation and run with the output "running"
this is perfectly legitimate if useless sample of creating an instnace of a thread and causing its run method to execute via a call to the start method. the thread class is part of the core java.lang package and does not need any explicit import statement. the reference to a thread target is an attempt to mislead with a reference to the method of using the runnable interface instead of simply inheriting from the thread super class.
answer to question 36)
1) randomaccessfile raf=new randomaccessfile("myfile.txt","rw");
the randomaccessfile is an anomaly in the java i/o architecture. it descends directly from object and is not part of the streams architecture
answer to question 37)
2) public int amethod(int i, int j) {return 99;}
3) protected void amethod (long l){}
4) private void anothermethod(){}
option 1 will not compile on two counts. one is the obvious one that it claims to return an integer. the other is that it is effectivly an attempt to redefine a method within the same class. the change of name of the parameter from i to z has no effect and a method cannot be overriden within the same class.
answer to question 38)
1) code must be written to cause a frame to close on selecting the system close menu
2) the default layout for a frame is the borderlayout manager
4) the gridbaglayout manager makes extensive use of the the gridbagconstraints class.
you can change the layout manager for a frame or any other container whenever you like