• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

a question about modifier

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
could someone tell me why
"an abstract method can't marked as synchronized,native,strictfp"?
Thank you.
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by chang nanny:
Hello,
could someone tell me why
"an abstract method can't marked as synchronized,native,strictfp"?



I think its simply because an abstract method is meant to be "empty" i.e. there should be nothing to synchronize in the first place.
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
synchronized is a keyword that refers to an implementation. Declaring a method as abstract requires that you do not provide an implementation. Therefore, there is nothing to synchronize. When you extend the abstract class and provide an implementation of an abstract method, you can use the synchronized modifier.

Mark
 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because, what would those qualifyers mean in the context of a method with no implementation, in a class that can't be instantiated?
synchronized - synchronizes on the object monitor of the containing object instance. An abstract method forces the class to be abstract, meaning you can't instantiate it.
native - specifies that the implementation of the method is in another language which is platform dependent (C/C++, VB, I guess...). For an abstract method there IS no implementation.... there's no code for it in ANY language
strictfp - tells the compiler to use Floating Point math that is completely portable and reliably gives the EXACT same answer, even on different Java VMs. It's a tip to the compiler about how to generate the bytecode for the method, and again, if there is no method definition, there's nothing for the compiler to do, strictfp or otherwise - it just doesn't make sense.
Bottom line, the combinations that don't make sense are disallowed by the compiler, not because it would have any bad effect (who cares what instructions you give the compiler about how to deal with a method that's not there?), but probably to help you spot the cases where you've (obviously) made a mistake.
-- Jon
 
chang nanny
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
abstract method can't mark as "static".
Could you tell the reason?
Thank you.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by chang nanny:

abstract method can't mark as "static".
Could you tell the reason?


A subclass of the abstract class must override the abstract method to provide an implementation of the method.
But static methods cannot be overridden.
So we have an unavoidable conflict if we try to use both static and abstract.
 
reply
    Bookmark Topic Watch Topic
  • New Topic