It's not a secret anymore!
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "K/B Pg135 Self Test" Watch "K/B Pg135 Self Test" New topic

K/B Pg135 Self Test

ced ron

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: 1873
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.
ced ron

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!
I agree. Here's the link:
subject: K/B Pg135 Self Test
jQuery in Action, 3rd edition