aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Final method 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 "Final method" Watch "Final method" New topic
Author

Final method

Kannan Raju
Ranch Hand

Joined: Jul 07, 2005
Posts: 44
Hi,

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.


SCJP1.4<br />SCWCD (in progress)
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
I feel A & E are correct options.
Let me know if i'm wrong.
Inline functions are some thing like this.
[ July 09, 2005: Message edited by: Srinivasa Raghavan ]

Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
newgen pras
Ranch Hand

Joined: Jun 01, 2005
Posts: 34
I guess A and B options are correct ...I don't know whether E is correct or not .. Pls correct me if am wrong
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
B is not correct.
A and E are correct.


Tony Morris
Java Q&A (FAQ, Trivia)
Kannan Raju
Ranch Hand

Joined: Jul 07, 2005
Posts: 44
According to Dan's web site: A, B and E are correct answers.
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
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.


42
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
[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.


"I'm not back." - Bill Harding, Twister
lauren bai
Greenhorn

Joined: Apr 08, 2005
Posts: 18
Kannan Raju: Can you give me the Dan's website?

Thanks

I also think B is right and have no idea about E.
Is inline machine-code is a test object for SCJP?


SCJP (In Progress)
Kannan Raju
Ranch Hand

Joined: Jul 07, 2005
Posts: 44
Dan's web site:

http://www.danchisholm.net/july21/topic/index.html
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
[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 ]
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
Is inline machine-code is a test object for SCJP?

No. Although it's not a part of the exam, it's better to understand concepts like this which 'll be used on job and for a better OO design.
[ July 12, 2005: Message edited by: Srinivasa Raghavan ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Final method