• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Bear Bibeault
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • salvin francis
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
Bartenders:
  • Jj Roberts
  • Carey Brown
  • Scott Selikoff

Abstract methods

 
Ranch Hand
Posts: 355
Redhat Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An abstract method can never be final. - Perfect.
An abstract method can never be private. - Agreed.
An abstract method can never be static. - Why?
An abstract method can never be native. - Why?
An abstract method can never be strictfp. - Why?

Please help. Thanks.
[ May 27, 2007: Message edited by: Faisal Pasha ]
 
Ranch Hand
Posts: 332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
non-native can be overriden by native and vice-versa
non-strictfp -||- strictfp
non-synchronized -||- synchronized

All of these are telling you something about how is method implemented.
But if you are saying that it is abstract method, then there is no implementation and combination with one of modifiers above is making no sense.

If it is abstract, it wont't be called (on this instance), so wheter it is synchronized, native, or strictfp is irrelevant.

I guess, there would be no harm, if this would be allowed, but Sun made it this way.
 
John Stone
Ranch Hand
Posts: 332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
static methods can't be overriden, only re-defined. This means, there is no polymorphism involved in calling static methods.
 
John Stone
Ranch Hand
Posts: 332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


gives on output:
A
 
Faisal Ahmad
Ranch Hand
Posts: 355
Redhat Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Many Thanks for your prompt replies!
I understood the static part perfectly. Still, the other things are unclear. Could you please add few more details? Thanks again!
 
John Stone
Ranch Hand
Posts: 332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
abstract - "I have no body"
synchronized - "My body is synchronized"

Compiler: "Oh, but you said you have no body, how can it be synchronized?!"

I guess, Sun considered those combinations as conflicting and forbid it.
 
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Faisal,

The native modifier specifies an implementation detail that an overriding method is not required to support. For that reason, an application of the native modifier to an abstract method declaration has no impact on the implementation of the overriding method in the subclass. Since the native modifier is useless when applied to an abstract method, the Java Language Specification requires the compiler to throw a compile-time exception to let the programmer know that the modifier has no impact.

The following code example demonstrates that a subclass can override a native method with a new implementation that is not native.



If you attempt to compile the above code example you will see that the compiler does not complain.

For the purposes of the exam the only thing that you need to know about the strictfp modifier is that it is indeed a Java modifier.
 
Faisal Ahmad
Ranch Hand
Posts: 355
Redhat Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much Dan and John! Your info has helped me a lot. Thanks again!
 
Yeast devil! Back to the oven that baked you! And take this tiny ad too:
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