格林模拟试题三参考答案(3)
添加时间: 2007-9-22 7:29:34 作者: JAVA认证考试 阅读次数:55 来源: http://www.d9soft.com
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
Answer to Question 39)
4) The code will compile without error
There are no restrictions on the level of nesting for inner/nested classes. Inner classes may be marked private. The main method is not declared as public static void main, and assuming that the commandline was java Droitwich it would not be invoked anyway.
Answer to Question 40)
1) super.oak=1;
2) oak=33;
3) Base.oak=22;
Because the variable oak is declared as static only one copy of it will exist. Thus it can be changed either through the name of its class or through the name of any instance of that class. Because it is created as an integer it canot be assigned a fractional component without a cast.
Answer to Question 41)
Obje Question 41)
4) Use the getText method of a Textfield and use the parseInt method of the Integer class
Here is an example of how you might do this
Integer.parseInt(txtInputValue.getText());
I'm not sure that a question on this actually will come up in the exam but it is a very useful thing to know in the real world.
Answer to Question 42)
4) none of the above
The wrapper classes are immutable. Once the value has been set it cannot be changed. A common use of the wrapper classes is to take advantage of their static methods such as Integer.parseInt(String s) that will returns an integer if the the value has been set it cannot be changed. A common use of the wrapper classes is to take advantage of their static methods such as Integer.parseInt(String s) that will returns an integer if the String contains one.
Answer to Question 43)
2) constructors cannot be overriden
Overloading constructors is a key technique to allow multiple ways of initialising classes. By definition, constructors have have no return values so option 3 makes no sense. Option 4 is the inverse of what happens as constructor code will execute starting from the oldest ancestor class downwards. You can test this by writing a class that inherits from a base class and getting the constructor to print out a message. When you create the child class you will see the order of constructor calling.
Answer to Question 44)
yield is a static method and causes whatever thread is currently executing to yield its cycles.
1) t.yield();
2) Thread.yield()
(Thanks Roseanne )
Java Doc for the Thread class
Answer to Question 45)
4) Compilation and run with an output of 99
The fact that the variable court is declared as private does not stop the constructor from being able to initialise it.
Answer to Question 46)
3) To be overriden a method must have the same name, parameter and return types
Option 1 is a sneaky one in that it should read overriden not overloaded. An overriden method must also have the same return type. Parameter names are purely a programmer convenience and are not a factor in either overloading and overriding. Parameter order is a factor however.
Answer to Question 47)
1) Compile time error
With the sun JDK it will produce the following error
"Only constructors can invoke constructors".
If you took out the call to super that causes this error the program would compile and at runtime it would output Base and then Checket as constructors are called from the oldest ancestor class downwards.
Answer to Question 48)
1) Static methods cannot be overriden to be non static
The JDK1.1 compiler will issue an error message "static methods cannot be overriden" if you atempt to do thiuot; if you atempt to do this. There is no logic or atempt to do this. There is no logic or reason why private methods should not be overloaded or that static methods should not be declared private. Option 4 is a jumbled up version of the limitations of exceptions for overriden methods
Answer to Question 49)
2) A program can suggest that garbage collection be performed but not force it
4) A reference becomes eligable for garbage collection when it is assigned to null
If a program keeps creating new references without any being discarded it may run out of memory. Unlike most aspects of Java garbage collection is platform dependent.
Answer to Question 55)
1) Compile time error
This might be considered a "gocha" or deliberate attempt to mislead you because i has been given the data type of long and the parameter must be of long and the parameter must be either a byte, char, short or int. If you attempt to compile this code with JDK 1.2 you will get an error that says something like "Incompatible type for switch, Explicit cast needed to convert long to int". Answering with option 2 would have been reasonable because if the parameter had been an integer type the lack of break statements would have caused this output. If you gave either of the answers you should probably revise the subject.
Answer to Question 56)
1) System.out.println(i++);
3) System.out.println(i);
4) System.out.println(i==);
The options for this question might look suspiciously easy if you are not aware of the effects of the post-increment operators. The ++ and == operations for examples 1 and 4 only come into effect after the output operations, ie after whatever else is done to them on that line of code. Option 2 should be fairly obvious as you should know that the single quote characters indicate a char value, ie storing the character rather than the numberical value for 0.
Answer to Question 57)
4) System.out.println( ((Agg) a).getFields());
The Base type reference to the instance of the class Agg needs to be cast from Base to Agg to get access to its methods.The method invoked depends on the object itself, not on the declared type. So, a.getField() tries to invoke a getField method in Base which does not exist. But the call to ((Agg)a).getField() will invoke the getField() in the Agg class. You will be unlucky to get a question as complex as this on the exam. If you think option 1 is valid, have a go at compiling the code.
Answer to Question 58)
2) compilation and output of false
A variable defined at class level will always be given a default value and the default value for the primitive type boolean is false
Answer to Question 59)
1) The x,y coordinates of an instance of MouseEvent can be obtained using the getX() and getY() methods
4) The time of a MouseEvent can be extracted using the getWhen method
If you chose option 4, referring to the mythical getTime method you have made a reasonable guess based on the normal conventions of Java . However the conventions do not always hold true. If you chose option 3 perhaps you are not as aware of the conventions as you should be.
Answer to Question 60)
2) The program will run and output only "fliton"
This question tests your knowledge of the principle that the finally clause will almost always run.
上一篇文章: 格林模拟试题三参考答案(2) 下一篇文章: JAVA题库:格林模拟试题三(下)(1)
相关文章:

