📄 scjp试题-scjpmockexam4.txt
字号:
Which is decimal 7.
http://www.jchq.net/tutorial/05_03Tut.htm
--------------------------------------------------------------------------------
Answer 30)
Back to Question 30
Objective 4.1)
1,2,3
public, private, static are all legal access modifiers for this inner class.
http://www.jchq.net/tutorial/04_01Tut.htm
--------------------------------------------------------------------------------
Answer 31)
Back to Question 31
Objective 7.1
3) Output of first0, first1, second0, second1
Note that this code overrides and calls the start method. If you wished to get the output mixed you would need to override the run method but call the start method.
http://www.jchq.net/tutorial/07_01Tut.htm
--------------------------------------------------------------------------------
Answer 32)
Back to Question 32)
Objective 8.1)
2) setLayout(new GridLayout(2,2));
Changing the layout manager is the same for an Applet or an application. Answer 1 is wrong though it might have been a reasonable name for the designers to choose. Answers 3 and 4 are incorrect because changing the layout manager always requires an instance of one of the Layout Managers and these are bogus methods.
Instead of creating the anonymous instance of the Layout manager as in option 2 you can also create a named instance and pass that as a parameter. This is often what automatic code generators such as Borland/Inprise JBuilder do.
http://www.jchq.net/tutorial/08_01Tut.htm
--------------------------------------------------------------------------------
Answer 33)
Back to Question 33)
Objective 7.1)
3) The code will cause an error at compile time
The error is caused because run should have a void not an int return type.
Any class that is implements an interface must create a method to match all of the methods in the interface. The Runnable interface has one method called run that has a void return type.The sun compiler gives the error
Method redefined with different return type: int run() was defined as void run();
http://www.jchq.net/tutorial/07_01Tut.htm
--------------------------------------------------------------------------------
Answer 34)
Back to Question 34)
Objective 7.1)
3) Compilation and output of 0 followed by 1
The creation of an anonymous class as a parameter to go is fairly strange as you would expect it to override a method in its parent class (Turing). You don’t have to though. The fact that class Turing extends Thread means the anonymous instance that is passed to go has a start method which then calls the run method.
http://www.jchq.net/tutorial/07_01Tut.htm
--------------------------------------------------------------------------------
Answer 35)
Back to Question 35
Objective 5.1)
4) Compile time error
The only operator overloading offered by java is the + sign for the String class. A char is a 16 bit integer and cannot be concatenated to a string with the + operator.
http://www.jchq.net/tutorial/05_01Tut.htm
--------------------------------------------------------------------------------
Answer 36)
Back to Question 36
Objective 5.2)
3) if(s.equalsIgnoreCase(s2))
String comparison is case sensitive so using the equals string method will not return a match. Using the==operator just compares where memory address of the references and noCaseMatch was just something I made up to give me a fourth slightly plausible option.
http://www.jchq.net/tutorial/05_02Tut.htm
--------------------------------------------------------------------------------
Answer 37)
Back to Question 37
Objective 8.1)
1) s.setBackground(Color.pink);
For speakers of the more British spelt English note that there is no letter u in Color. Also the constants for colors are in lower case.
http://www.jchq.net/tutorial/08_01Tut.htm
--------------------------------------------------------------------------------
Answer 38)
Back to Question 38)
Objective 11.1)
4) The File class does not support directly changing the current directory.
This seems rather surprising to me, as changing the current directory is a very common requirement. You may be able to get around this limitation by creating a new instance of the File class passing the new directory to the constructor as the path name.
http://www.jchq.net/tutorial/11_01Tut.htm
--------------------------------------------------------------------------------
Answer 39)
Back to Question 39)
Objective 8.1)
1)With a fixed font you will see 5 characters, with a proportional it will depend on the width of the characters
With a proportional font the letter w will occupy more space than the letter i. So if you have all wide characters you may have to scroll to the right to see the entire text of a TextField.
http://www.jchq.net/tutorial/08_01Tut.htm
--------------------------------------------------------------------------------
Answer 40)
Back to Question 40)
Objective 6.2
3) On the line After //Two put super(10);
Constructors can only be invoked from within constructors.
http://www.jchq.net/tutorial/06_02Tut.htm
--------------------------------------------------------------------------------
Answer 41)
Back to Question 41)
Objective 5.4)
3) 10 and 40
when a parameter is passed to a method the method receives a copy of the value. The method can modify its value without affecting the original copy. Thus in this example when the value is printed out the method has not changed the value.
http://www.jchq.net/tutorial/05_04Tut.htm
--------------------------------------------------------------------------------
Answer 42)
Back to Question 42
Objective 1.1
4) for(int i=0; i< ia.length;i++)
Although you could control the looping with a literal number as with the number 4 used in option 3, it is better practice to use the length property of an array. This provides against bugs that might result if the size of the array changes. This question also checks that you know that arrays starts from zero and not One as option 3 starts from one. Remember that array length is a field and not a function like the String length() method.
http://www.jchq.net/tutorial/01_01Tut.htm
--------------------------------------------------------------------------------
Answer 43)
Back to Question 43)
Objective 1.2
1) Error at compile time
This is a slightly sneaky one as it looks like a question about constructors, but it is attempting to test knowledge of the use of the private modifier. A top level class cannot be defined as private. If you didn’t notice the modifier private, remember in the exam to be real careful to read every part of the question.
http://www.jchq.net/tutorial/01_02Tut.htm
--------------------------------------------------------------------------------
Answer 44)
Back to Question 44
Objective 4.5)
3)10
The name of the class might give you a clue with this question, Oct for Octal. Prefixing a number with a zero indicates that it is in Octal format. Thus when printed out it gets converted to base ten. 012 in octal means the first column from the right has a value of 2 and the next along has a value of one times eight. In decimal that adds up to 10.
http://www.jchq.net/tutorial/04_05Tut.htm
--------------------------------------------------------------------------------
Answer 45)
Back to Question 45
Objective 1.2)
1) Error at compile time
The variable i is created at the level of amethod and will not be available inside the method multi.
http://www.jchq.net/tutorial/01_02Tut.htm
Answer 46)
Back to Question 46
Objective 10.1)
1) Set
The Set interface ensures that its elements are unique, but does not order the elements. In reality you probably wouldn’t create your own class using the Set interface. You would be more likely to use one of the JDK classes that use the Set interface such as HashSet or TreeSet.
http://www.jchq.net/tutorial/10_01Tut.htm
--------------------------------------------------------------------------------
Answer 47)
Back to Question 47
Objective 10.1)
4) Vector v=new Vector(100);
v.addElement("99")
A vector can only store objects not primitives. The parameter "99" for the addElement method pases a string object to the Vector. Option 1) creates a vector OK but then uses array syntax to attempt to assign a primitive. Option 2 also creates a vector then uses correct Vector syntax but falls over when the parameter is a primitive instead of an object.
http://www.jchq.net/tutorial/10_01Tut.htm
--------------------------------------------------------------------------------
Answer 48)
Objective 8.1)
Back to Question 48
3) The lower part of the word Dolly will be seen at the top of the form
The Second parameter to the drawstring method indicates where the baseline of the string will be placed. Thus the 3rd parameter of 10 indicates the Y coordinate to be 10 pixels from the top of the Frame. This will result in just the bottom of the string Dolly showing up or possibly only the descending part of the letter y.
http://www.jchq.net/tutorial/08_01Tut.htm
--------------------------------------------------------------------------------
Answer 49)
Back to Question 49)
Objective 9.1)
1) Compile time error referring to a cast problem
This is a bit of a sneaky one as the Math.random method returns a pseudo random number between 0 and 1, and thus option 3 is a plausible Answer. However the number returned is a double and so the compiler will complain that a cast is needed to convert a double to an int.
http://www.jchq.net/tutorial/09_01Tut.htm
--------------------------------------------------------------------------------
Answer 50)
Objective 2.3)
Back to question 50
1) public void ioCall ()throws IOException{
DataInputStream din = new DataInputStream(System.in);
din.readChar();
}
If a method might throw an exception it must either be caught within the method with a try/catch block, or the method must indicate the exception to any calling method by use of the throws statement in its declaration. Without this, an error will occur at compile time.
http://www.jchq.net/tutorial/02_03Tut.htm
--------------------------------------------------------------------------------
Answer 51)
Objective 1.2)
Back to Question 51)
3) A compile time error
Because only one instance of a static method exists not matter how many instance of the class exists it cannot access any non static variables. The JVM cannot know which instance of the variable to access. Thus you will get an error saying something like
Can’t make a static reference to a non static variable
http://www.jchq.net/tutorial/01_02Tut.htm
--------------------------------------------------------------------------------
Answer 52)
Objective 8.2)
Back to Question 52)
2) Create an instance of the GridBagConstraints class, set the weightx field and then pass the GridBagConstraints instance with the component to the setConstraints method of the GridBagLayout class.
The Key to using the GridBagLayout manager is the GridBagConstraint class. This class is not consistent with the general naming conventions in the java API as you would expect that weightx would be set with a method, whereas it is a simple field (variable).
If you have a copy of the Roberts and Heller Java2 Guide that says the exam does not cover the GridBagLayout, this is an error. You can confirm this by looking at the online errata at
http://www.sybex.com/cgi-bin/rd_err_temp.pl?2463err.html
http://www.jchq.net/tutorial/08_02Tut.htm
--------------------------------------------------------------------------------
Answer 53)
Objective 11.1)
Back to Question 53)
2) Return the name of the parent directory
3) Delete a file
It is surprising that you can’t change the current directory. It is not so surprising that you can’t tell if a file contains text or binary information.
http://www.jchq.net/tutorial/11_01Tut.htm
--------------------------------------------------------------------------------
Answer 54)
Back to Question 54)
Objective 7.1
2) Output of One One Two Two
Answer 3 would would be true if the code called the start method instead of the run method (well it is on my Windows machine anyway, I’m not sure it would be for ever implementation of Java Threads). If you call the run method directly it just acts as any other method and does not return to the calling code until it has finished executing.
http://www.jchq.net/tutorial/07_01Tut.htm
--------------------------------------------------------------------------------
Answer 55)
Objective 3.1)
Back to Question 55)
1) You cannot be certain when garbage collection will run
Although there is a Runtime.gc(), this only suggests that the Java Virtual Machine does its garbage collection. You can never be certain when the garbage collector will run. Roberts and Heller is more specific abou this than Boone. This uncertainty can cause consternation for C++ programmers who wish to run finalize methods with the same intent as they use destructor methods.
http://www.jchq.net/tutorial/03_01Tut.htm
--------------------------------------------------------------------------------
Answer 56)
Objective 8.1)
Back to Question 56)
4) The fill field of the GridBagConstraints class
Unlike the GridLayout manager you can set the individual size of a control such as a button using the GridBagLayout manager. A little background knowledge would indicate that it should be controlled by a setSomethingOrOther method, but it isn’t.
If you have a copy of the Roberts and Heller Java2 Guide that says the exam does not cover the GridBagLayout, this is an error. You can confirm this by looking at the online errata at
http://www.sybex.com/cgi-bin/rd_err_temp.pl?2463err.html
http://www.jchq.net/tutorial/08_01Tut.htm
--------------------------------------------------------------------------------
Answer 57)
Objective 10.1)
Back to Question 57)
4) A collection for storing bits as on-off information, like a vector of bits
This is the description given to a bitset in Bruce Eckels "Thinking in Java" book. The reference to unique sequence of bits was an attempt to mislead because of the use of the word Set in the name bitset. Normally something called a set implies uniqueness of the members, but not in this context.
http://www.jchq.net/tutorial/10_01Tut.htm
--------------------------------------------------------------------------------
Answer 58)
Back to Question 58)
Objective 4.1)
4)Compile error: Superclass Class1.Base of class Class1.Class1 not found
Using the package statement has an effect similar to placing a source file into a different directory. Because the files are in different packages they cannot see each other. The stuff about File1 not having been compiled was just to mislead, java has the equivalent of an "automake", whereby if it was not for the package statements the other file would have been automatically compiled.
http://www.jchq.net/tutorial/04_01Tut.htm
--------------------------------------------------------------------------------
Answer 59)
Back to Question 59)
Objective 6.2)
4) Output of Over.amethod()
The names of parameters to an overridden method is not important.
http://www.jchq.net/tutorial/06_02Tut.htm
--------------------------------------------------------------------------------
Answer 60)
Objective 8.1)
Back to Question 60)
1) Set the gridy value of the GridBagConstraints class to a value increasing from 1 to 4
Answer 4 is fairly obviously bogus as it is the GridBagConstraints class that does most of the magic in laying out components under the GridBagLayout manager. The fill value of the GridBagConstraints class controls the behavior inside its virtual cell and the ipady field controls the internal padding around a component.
If you have a copy of the Roberts and Heller Java2 Guide that says the exam does not cover the GridBagLayout, this is an error. You can confirm this by looking at the online errata at
http://www.sybex.com/cgi-bin/rd_err_temp.pl?2463err.html
http://www.jchq.net/tutorial/08_01Tut.htm
--------------------------------------------------------------------------------
1) Objective 4.5
2) Objective 4.1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -