This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes K/B Pg135 Self Test Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "K/B Pg135 Self Test" Watch "K/B Pg135 Self Test" New topic
Author

K/B Pg135 Self Test

ced ron
Greenhorn

Joined: Oct 08, 2003
Posts: 5
Hi everyone,
I'm planning to take my SCJP in 2 months time. Currently reading K/B book and need some help in the Chap 2 self test on pg135.
Q5: 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() {}
Answer: E. 5 (1,2,4,5,6)
What I don't understand is why option 5 is legal? Without the curly braces, isn't it an abstract method? If it is, then it shouldn't be marked private and native. Does anyone feel there should be a pair of curly braces?
Please help. Thanks!
Zak Nixon
Ranch Hand

Joined: Sep 27, 2003
Posts: 126
I have never messed around with native calls in Java, but
I have seen this form before, and it is correct.
It is not an abstract method, just native methods have no
body to them.
<Dont fully understand...>
Zak Nixon
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
Hi Ced
native methods are implemented in C/C++ code and then called from Java. Hence they don't have corresponding implementation in Java class. So, it allows having just decalration of native method like abstract method w/o using word 'abstract'. Also, abstract means that a subclass can define it BUT native keyword means that the implementation is there in one of the libraries created by the user and its not possible to have it implemented in Java itself. So, abstract would not make sense here if we put 'abstract' keyword in front of a native method declaration...
Hope its clear.
Regards
Maulin
ced ron
Greenhorn

Joined: Oct 08, 2003
Posts: 5
Thanks Zak and Maulin for your prompt reply!
Guess I would have to be careful in assuming abstract method to be "method with no curly braces and ends with a semi-colon". Now that I take a second look at the question, it didn't ask for interface method declaration but a general method declaration else option 5 would have hit a compilation error.
ok, chapter 2 offically closed. 7 more to go!
Thanks guys! You're great!
 
wood burning stoves
 
subject: K/B Pg135 Self Test
 
Similar Threads
Confusing SCJP question!
Legal method declarations
doubt in K&B book.. pg:135
Sierra's SCJP book SELF TEST
Legal Method Declarations