Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

main , modifiers and inheritance

 
Samuel Jaeson
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can main be marked final, native, strictfp or synchronized
whats the logic / purpose
+
are final ,native, strictfp or synchronized
inheritated and checked while overloading or overriding
whats the rule
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "logic/purpose" in making a main method final, strictfp, or synchronized is the same as in making any other method final, strictfp, or synchronized. In general, final methods cannot be overridden; strictfp methods have consistent floating point behavior across different platforms; and synchronized methods cannot be executed unless the calling thread obtains the object/class lock.

I don't know whether main (as a Java entry point) can be native.

Because methods are identified by their (fully qualified) class name, method name, and ordered argument types, overloading is just a variation in naming. From the compiler's perspective, overloaded methods are unrelated. So the modifiers final, strictfp, synchronized, and native have no relevance to overloading. Also, an overloaded version of main (with some argument other than a String array) will not function as an entry point.

final methods are inherited, but -- by definition -- cannot be overridden. (If you want a method to be "invisible" to a subclass, use private.)

The synchronized modifier is not passed via inheritance.
[ January 10, 2005: Message edited by: marc weber ]
 
Steven Bell
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course this goes back to the issue of how static methods are not really overridden, but rather 'hidden'.

making a main method final, really wouldn't seem to do much.
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course this goes back to the issue of how static methods are not really overridden, but rather 'hidden'.

making a main method final, really wouldn't seem to do much.


Actually, final works the same for a static method. It prohibits the hiding of an inherited static method by a method in a subclass. BTW, the JLS distinguishes hiding, as I defined it, from shadowing, giving a member the same name as a member in an enclosing scope.
 
Steven Bell
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I apoligise. It looks like I was wrong. Good thing there are smart people here to correct me.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic