SCJP试题-SCJPMockExam4

来源:java认证发布时间:2012-11-12 12:48:14java认证视频



Answer 3)
back to Question 3) 
Objective 4.1)

2 and 3 will compile without error. 


1 will not compile because any package declaration must come before any other code. Comments may appear anywhere

http://www.jchq.net/tutorial/04_01Tut.htm . 


--------------------------------------------------------------------------------

Answer 4)
Back to question 4) 
Objective 4.5) 

1) A byte is a signed 8 bit integer. 

http://www.jchq.net/tutorial/04_05Tut.htm



--------------------------------------------------------------------------------

Answer 5)
Back to question 5) 
Objective 4.2) 

4) Exception raised: "java.lang.ArrayIndexOutOfBoundsException: 2" 

Unlike C/C++ java does not start the parameter count with the program name. It does however start from zero. So in this case zero starts with good, morning would be 1 and there is no parameter 2 so an exception is raised. 

http://www.jchq.net/tutorial/04_02Tut.htm



--------------------------------------------------------------------------------

Answer 6)
Back to question 6) 
Objective 4.3) 

1) if 
3) goto 
4) while 
5) case 


then is not a Java keyword, though if you are from a VB background you might think it was. Goto is a reserved word in Java. 

http://www.jchq.net/tutorial/04_03Tut.htm



--------------------------------------------------------------------------------

Answer 7)
Back to Question 7) 
Objective 4.1) 

2) variable2 
3) _whatavariable 
4) _3_ 
5) $anothervar 


An identifier can begin with a letter (most common) or a dollar sign($) or an underscore(_). An identifier cannot start with anything else such as a number, a hash, # or a dash -. An identifier cannot have a dash in its body, but it may have an underscore _. Choice 4) _3_ looks strange but it is an acceptable, if unwise form for an identifier. 

http://www.jchq.net/tutorial/04_01Tut.htm



--------------------------------------------------------------------------------

Answer 8)
Back to Question 8) 
Objective 4.4) 

4) 0 

Class level variables are always initialised to default values. In the case of an int this will be 0. Method level variables are not given default values and if you attempt to use one before it has been initialised it will cause the 

Error Variable i may not have been initialized
type of error.

http://www.jchq.net/tutorial/04_04Tut.htm



--------------------------------------------------------------------------------

Answer 9)
Back to Question 9) 
Objective 4.4) 

3 ) 2 

No error will be triggered. 

Like in C/C++, arrays are always referenced from 0. Java allows an array to be populated at creation time. The size of array is taken from the number of initializers. If you put a size within any of the square brackets you will get an error. 

http://www.jchq.net/tutorial/04_04Tut.htm



--------------------------------------------------------------------------------

Answer 10)
Back to question 10) 
Objective 4.4) 

3) 0 

Arrays are always initialised when they are created. As this is an array of ints it will be initalised with zeros. 

http://www.jchq.net/tutorial/04_04Tut.htm



--------------------------------------------------------------------------------

Answer 11)
Back to Question 11) 
Objective 1.2 

3) Error Mine must be declared abstract 


A class that contains an abstract method must itself be declared as abstract. It may however contain non abstract methods. Any class derived from an abstract class must either define all of the abstract methods or be declared abstract itself. 

http://www.jchq.net/tutorial/01_02Tut.htm



--------------------------------------------------------------------------------

Answer 12)
Back to Question 12) 
Objective 2.1) 

3) one, two, default 

Code will continue to fall through a case statement until it encounters a break. 

http://www.jchq.net/tutorial/02_01Tut.htm



--------------------------------------------------------------------------------

Answer 13)
Back to Question 13) 
Objective 4.1) 

2) default, zero 

Although it is normally placed last the default statement does not have to be the last item as you fall through the case block. Because there is no case label found matching the expression the default label is executed and the code continues to fall through until it encounters a break. 

http://www.jchq.net/tutorial/04_01Tut.htm



--------------------------------------------------------------------------------

Answer 14)
Back to Question 14) 
Objective 5.1 

2,3 

Example 1 will not compile because if must always test a boolean. This can catch out C/C++ programmers who expect the test to be for either 0 or not 0. 

http://www.jchq.net/tutorial/05_01Tut.htm



--------------------------------------------------------------------------------

Answer 15)
Back to Question 15) 
Objective 11.5) 

3) No such file found, doing finally, -1 

The no such file found message is to be expected, however you can get caught out if you are not aware that the finally clause is almost always executed, even if there is a return statement. 

http://www.jchq.net/tutorial/11_05Tut.htm



--------------------------------------------------------------------------------

Answer 16)
Back to Question 16) 
Objective 6.2)

1) Methods cannot be overriden to be more private

Static methods cannot be overriden but they can be overloaded. There is no logic or reason why private methods should not be overloaded. Option 4 is a jumbled up version of the limitations of exceptions for overriden methods 

http://www.jchq.net/tutorial/06_02Tut.htm
http://java.sun.com/docs/books/tutorial/java/javaOO/override.html 




--------------------------------------------------------------------------------

Answer 17)
Back to Question 17) 
Objective 6.2)

3) Runtime Exception 

Without the cast to sub you would get a compile time error. The cast tells the compiler that you really mean to do this and the actual type of b does not get resolved until runtime. Casting down the object hierarchy as the compiler cannot be sure what has been implemented in descendent classes. Casting up is not a problem because sub classes will have the features of the base classes. This can feel counter intuitive if you are aware that with primitives casting is allowed for widening operations (ie byte to int). 

http://www.jchq.net/tutorial/06_02Tut.htm



--------------------------------------------------------------------------------

Answer 18)
Back to question 18) 
Objective 5.1) 

1) System.out.println( -1 >>> 2);will output a result larger than 10
2) System.out.println( -1 >>> 2); will output a positive number 
3) System.out.println( 2 >> 1); will output the number 1 

You can test this with the following class

public class shift{

static int i=2;

public static void main(String argv[]){

System.out.println( -1 >>> 2);

System.out.println( -1 >>> 2);

System.out.println( 2 >> 1);

}

}
Java does not have a <<< operator. The operation 1 << 2 would output 4 

Because of the way twos complement number representation works the unsigned right shift operation means a small shift in a negative number can return a very large value so the output of option 1 will be much larger than 10.

The unsigned right shift places no significance on the leading bit that indicates the sign. For this shift the value 1 of the bit sign is replaced with a zero turning the result into a positive number for option 2.

http://www.jchq.net/tutorial/05_01Tut.htm



--------------------------------------------------------------------------------

Answer 19)
Back to Question 19) 
Objective 7.1)

4) Compilation and probably output of "vandelur" but possible output of "vandeleur 0 1 2 3"

If that seems a vauge answer it is because you cannot be certain of the system that the underlying OS uses for allocating cycles for a Thread. The chances are that once the thread has been spun off in the call to start in the method piggy the main method will run to completion and the value of sName will still be vandeluer before the Thread modifies it. You cannot be certain of this though.

Just because sName is static does not mean that passing it to a method gives the method the original copy. The method only sees a locally created copy and any changes to it will not be reflected on return to the calling method. 

http://www.jchq.net/tutorial/07_01Tut.htm


--------------------------------------------------------------------------------

Answer 20)
Back to Question 20) 
Objective 8.1) 

3) One button occupying the entire frame saying Bye 

The default layout manager for a Frame is a border layout. If directions are not given (ie North, South, East or West), any button will simply go in the centre and occupy all the space. An additional button will simply be placed over the previous button. What you would probably want in a real example is to set up a flow layout as in 

setLayout(new FlowLayout()); 

Which would allow the buttons to both appear side by side, given the appropriate font and size.
Applets and panels have a default FlowLayout manager

http://www.jchq.net/tutorial/08_01Tut.htm



--------------------------------------------------------------------------------

Answer 21)
Back to Question 21) 
Objective 2.2) 

1,2 

Value for i=1 Value for j=1 
Value for i=2 Value for j=1 


The statement continue outer causes the code to jump to the label outer and the for loop increments to the next number. 

http://www.jchq.net/tutorial/02_02Tut.htm



--------------------------------------------------------------------------------

Answer 22)

Objective 7.3)

4) Runtime error, an exception will be thrown

A call to wait/notify must be within synchronized code. With JDK1.2 this code throws theerror message 

java.lang.IllegalMonitorStateException: current thread not owner
at java.lang.Object.wait(Native Method)
at java.lang.Object.wait(Object.java:424)
at DSRoss.notwait(Compiled Code)
at DSRoss.run(Agg.java:21)
Back to Question 22) 
http://www.jchq.net/tutorial/07_03Tut.htm



--------------------------------------------------------------------------------

Answer 23)
Back to Question 23) 
Objective 2.3) 

2,3 

Options 1, & 4 will not compile as they attempt to throw Exceptions not declared in the base class. Because options 2 and 3 take a parameter of type long they represent overloading not overriding and there is no such limitations on overloaded methods. 

http://www.jchq.net/tutorial/02_03Tut.htm



--------------------------------------------------------------------------------

Answer 24)
Back to Question 24) 
Objective 8.1) 

3) System.out.println(Math.ceil(-4.7)); 

Options 1 and 2 will produce -5 and option 4 will not compile because the min method requires 2 parameters. 

http://www.jchq.net/tutorial/08_01Tut.htm



--------------------------------------------------------------------------------

Answer 25)
Back to Question 25 
Objective 4.5)

3) Error: Cant convert java lang Integer 

The wrapper classes cannot be used like primitives. 

Wrapper classes have similar names to primitives but all start with upper case letters. 
Thus in this case we have int as a primitive and Integer as a wrapper. The objectives do not specifically mention the wrapper classes but don’t be surprised if they come up. 

http://www.jchq.net/tutorial/04_05Tut.htm



--------------------------------------------------------------------------------

Answer 26)
Back to Question 26) 
Objective 4.5) 

2) ic 

This is a bit of a catch question. Anyone with a C/C++ background would figure out that addressing in strings starts with 0 so that 1 corresponds to i in the string Bicycle. The catch is that the second parameter returns the endcharacter minus 1. In this case it means instead of the "icy" being returned as intuition would expect it is only "ic".

http://www.jchq.net/tutorial/04_05Tut.htm



--------------------------------------------------------------------------------

Answer 27)
Back to Question 27) 
Objective 9.2) 

3) s.indexOf(’v’); 

charAt returns the letter at the position rather than searching for a letter and returning the position, MID is just to confuse the Basic Programmers, indexOf(s,’v’); is how some future VB/J++ nightmare hybrid, might perform such a calculation. 

http://www.jchq.net/tutorial/04_05Tut.htm


--------------------------------------------------------------------------------

Answer 28)
Objective 5.1)
Back to Question 28 

1) s3=s1 + s2; 

Java does not allow operator overloading as in C++, but for the sake of convenience the + operator is overridden for strings. 

http://www.jchq.net/tutorial/05_01Tut.htm


视频学习

我考网版权与免责声明

① 凡本网注明稿件来源为"原创"的所有文字、图片和音视频稿件,版权均属本网所有。任何媒体、网站或个人转载、链接转贴或以其他方式复制发表时必须注明"稿件来源:我考网",违者本网将依法追究责任;

② 本网部分稿件来源于网络,任何单位或个人认为我考网发布的内容可能涉嫌侵犯其合法权益,应该及时向我考网书面反馈,并提供身份证明、权属证明及详细侵权情况证明,我考网在收到上述法律文件后,将会尽快移除被控侵权内容。

最近更新

社区交流

考试问答