• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Sierra's SCJP book SELF TEST

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
https://coderanch.com/t/241758/java-programmer-SCJP/certification/Native-methods-explanation
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic