• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Final method

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess A and B options are correct ...I don't know whether E is correct or not .. Pls correct me if am wrong
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
B is not correct.
A and E are correct.
 
Kannan Raju
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
According to Dan's web site: A, B and E are correct answers.
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[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.
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Kannan Raju
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dan's web site:

http://www.danchisholm.net/july21/topic/index.html
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[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
Posts: 1228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic