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