This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Sierra's SCJP book SELF TEST Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Sierra Watch "Sierra New topic
Author

Sierra's SCJP book SELF TEST

Alexander Heinhold
Greenhorn

Joined: Apr 12, 2003
Posts: 2
Hello JavaRanchers,
during my prep for the SCJP examn using Kathy Sierra's hilarious new book, I encountered the following Self Test question on p. 135:
5. How many of the following are legal method declarations?
1 � protected abstract void m1();
2 � static final void m1(){}
3 � transient private native void m1() {}
4 � synchronized public final void m1() {}
5 � private native void m1();
6 � static final synchronized protected void m1() {}
A. 1
B. 2
C. 3
D. 4
E. 5
F. All of them
and the following answer on p. 141:
5. E. Statements 1, 2, 4, 5, and 6 are legal declarations.
A, B, C, D, and F are incorrect because the only illegal declaration is 3; transient
applies only to variable declarations, not to method declarations. As you can see from these
other examples, method declarations can be very extensive.
Now, what confuses me about this, is that in my view declaration no 5 -
private native void m1();
also must wind up in a compiler error, since there are no curly braces but a semicolon instead (as is in no 1 for marking it as an abstract method) and it's not signed abstract. So, since two declarations won't compile, answer "D. 4" would be correct in my view.
Would anybody agree on this or rather suggest I should change profession and sell potatoes instead of trying to take this examn?

Warmest Regards, Alexander
Ryan Wilson
Ranch Hand

Joined: Apr 16, 2003
Posts: 65
Alex do you need a partner selling potatoes?
I took a look at this question last night and was confused myself.
This thread sheds some light on it
http://www.coderanch.com/t/241758/java-programmer-SCJP/certification/Native-methods-explanation
El Zhang
Greenhorn

Joined: May 13, 2003
Posts: 7
Alex, just like abstract, native indicates the body of a method is somewhere else (in a library), where as abstract indicates the method implementation can be found in a subclass.
you can't put the curly braces there, so in the 3rd method declaration, there are two errors:
1.Transient applies only to variable declarations.
2.Native methods can't have a body
Hope this helps
Alexander Heinhold
Greenhorn

Joined: Apr 12, 2003
Posts: 2
Hello Elton,
this explains everything. It's just not enough to know that the native modifier only applies to methods - you also need to know how to implement a native method (which, of course, I didn't need to yet).
Regarding Sierra's/Bates' definitely brilliant exam book, this is something like a trick question, since they assure "you don't need to know how to use native methods for the exam" (p. 90)
(Still thinking about the potatoe matter...)
Thanks anyway Elton...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sierra's SCJP book SELF TEST