This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes main , modifiers and inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "main , modifiers and inheritance" Watch "main , modifiers and inheritance" New topic
Author

main , modifiers and inheritance

Samuel Jaeson
Greenhorn

Joined: Dec 23, 2004
Posts: 9
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

Joined: Aug 31, 2004
Posts: 11343

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 ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
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

Joined: Mar 13, 2004
Posts: 1272
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.


Mike Gershman
SCJP 1.4, SCWCD in process
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
I apoligise. It looks like I was wrong. Good thing there are smart people here to correct me.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: main , modifiers and inheritance