Forums Register Login

Passed Mock Exam with 75% --> Some questions about wrong answers...

+Pie Number of slices to send: Send
Hi there,

I just made the first mock exam from the SCJP book. Some questions occurred, where I am a little bit unsure:


1) If I use , do I still access the Strings with agrs[0], agrs[1] and so on?




2) Method: --> if z has the value 3, the method call returns 3, not 4, right?




3) --> the go method has "void" as return value, so that is not possible (because it does not return anything. But what else is not allowed? I do not understand this?
Does String s; or String s = "test"; return anything? Can someone please explain me this rule?




4) I thought that an interface declaration MUST be declared public? (I know that methods are declared public abstract implicitly, and constants are declared static final implicitly)




5) Why does USUALLY the developer throw the NumberFormatException? I never did :-) Isn't this thrown USUALLY by the JVM (e.g. when I divide 10 through 0), just like NullPointerException, ClassCastException, and so on?




6) Can you please explain me the "switch and final" rule?
final int x = 3 may be used as switch expression, but short = 3 must not? Why?





I think with 75% in this mock exam (although I have seen some of the questions before), I am on a good way - with some more learning I am ready to try the exam :-)

I just downloaded the "ExamLab for SCJP 6.0" - do you think this is the best way now to improve my knowledge at this point?


Best regards,
Kai
+Pie Number of slices to send: Send
1) yes
2) yes
3) The second part of assert statement after : cannot have a call to a method returning void. See this
4) Interfaces are not required to be declared public
5) ArithmeticException is thrown when 10 is divided by 0 not NumberFormatException. NumberFormatException is generally thrown by parseXXX methods like parseInt to indicate that the parsed String cannot be parsed into a number.
6) I cannot understand this question of yours. You've written short = 3 which is not even a legal java syntax...
+Pie Number of slices to send: Send
Thanks for your quick reply.

Assert:

Expression2 is an expression that has a value. (It cannot be an invocation of a method that is declared void.)


Ok, so the second expression can be anything else, but not a call to a method that is declared void?




Question 6 again, sorry for my mistake:
Can you please explain me the "switch and final" rule?
final int x = 3 may be used as switch expression, but short y = 3 must not? Why? e.g:



Why fails the second example and what is the specific rule to remember? Does a switch expression always have to be declared final or be an Enum?


+Pie Number of slices to send: Send
 

Kai Wähner wrote:
.........



Why fails the second example and what is the specific rule to remember? Does a switch expression always have to be declared final or be an Enum?



Does this fail? switch expression need not be a final, but the case!
+Pie Number of slices to send: Send
 

Does this fail? switch expression need not be a final, but the case!



Oh, ok. You are right. So only the case expression must be final or a Enum...
+Pie Number of slices to send: Send
 

Kai Wähner wrote:

Does this fail? switch expression need not be a final, but the case!



Oh, ok. You are right. So only the case expression must be final or a Enum...



If you've enough time, and knowledge hungry, have a look on this
+Pie Number of slices to send: Send
Sure, I am knowledge hungry :-) Thanks...
+Pie Number of slices to send: Send
As for assert statement, you cannot put "anything" after : in assert statement. It should be an expression which returns a value. Check the documentation of AssertionError class, it has a number of constructors which take primitive types and Object as argument. So the part after : can be anything which returns a primitive or Object as a value...
No prison can hold Chairface Chippendale. And on a totally different topic ... my stuff:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1080 times.
Similar Threads
java
Bill Brogden's 1.4 Mock Question
Six java questions: Could anyone answer
Traps to be aware of in any SCJP test !!!!! :)
Sun sample exam - Item 6
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 00:08:52.