Here is a question from Dan's web site. I am not clear with the option E. What is the meaning of "inline the body"?
Which of the following statements are true?
a. A final method can not be overridden. b. All methods declared in a final class are implicitly final. c. The methods declared in a final class must be explicitly declared final or a compile-time error occurs. d. It is a compile-time error if a private method is declared final. e. A machine-code generator can inline the body of a final method.
B is correct. The word is implicitly. A final class cannot be subclassed therefore there's no way to override its methods anywhere. Not being allowed/capable to override a method is the definition of a final method.
[Jeroen]: Not being allowed/capable to override a method is the definition of a final method.
No. A final method may not be overridden; however this does not necessarily imply that any method which may not be overridden is final. "A implies B" does not imply that "B implies A".
[Jeroen]: The word is implicitly.
That's a good word, one which the JLS uses fairly often when it's actually called for. However I don't think you'll be able to find any statement in the JLS which implies that methods of a final class are implicitly final. That's probably because the JLS authors felt it was really irrelevant whether the methods of a final class were technically final or not - as long as you can't extend the class itself, there's no possible way to override one of its methods. Regardless of whether the methods themselves are "final" or not. So, it really does not matter in any way whether option B is true or not. The important point is that a final class cannot ever be extended, which means that a method of a final class cannot ever be overridden. As long as you understand that, (b) is really irrelevant.
[lauren bai ]: I also think B is right and have no idea about E.
No, B is wrong, E is right. Here's a simple demo:
Now as it happens, there is a logical problem with this argument, and there is a better argument which replaces it (which has already been made in the thread above, actually). But for anyone who hasn't been following the previous discussion, this short code sample might be more convincing.
Is inline machine-code is a test object for SCJP?
No. Nor is it important that you understand what "implicitly final" really means, for purposes of the exam. The only things here that you need to know for the exam are: (1) a final method cannot be overridden, and (2) a method of a final class cannot be overridden. [ July 11, 2005: Message edited by: Jim Yingst ]