aspose file tools*
The moose likes Beginning Java and the fly likes Main() Overloading Vs Main() Overridding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Main() Overloading Vs Main() Overridding" Watch "Main() Overloading Vs Main() Overridding" New topic
Author

Main() Overloading Vs Main() Overridding

Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

Hi,
I have the below clarifications.I have gone through various web sites but did not find "CORRECT ACCEPTED ANSWERS" for the below Questions.






I'm pretty much

Please clarify the above concepts to me..
Highly appreciate if you can clarify these concepts to me...

--
Deepak Lal


When The Going Gets Tougher,The Tougher gets Going
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38765
    
  23
When the going gets tough . . . Deepak Lal tells us why he thinks a static method can be overridden. We have a suitable FAQ.
Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

I'm pretty much convinced with the FAQ Camphell Ritchiee but if example's for Main() method Overloading are provided..it would be helpful.

The FAQ clearly states that
1>static methods "cannot be overridden".They can be "HIDDEN" i.e a static method in superclass will hide another static method in subclass.and hence static method in super class will be executed.(example:foo.classMethod())
2>static methods are class methods.
3>static methods do not support run time polymorphism.
4>static methods are called at compile time.

Please correct me for the above interpretations if I'm wrong..

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41809
    
  62
Overloading is a basic concept of object-oriented programming. Doesn't the book or tutorial you're learning with provide examples of it?


Ping & DNS - my free Android networking tools app
Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

Yes, Mr Ulf Dittmer (sheriff) i do agree with you about concepts of overloading.but my query is different



Can a public static void main method in java be overloaded as shown below ?
I,e



Can i have something like above stated.what will happen when i execute the above program?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38765
    
  23
It is actually pretty obvious what will happen if you execute that application; have you tried it?

If you can't understand why it behaves like that, and can't work out how to get it to behave differently, then please ask again.
Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

Hi campbell richtie,


campbell richtie's Comments :

It is actually pretty obvious what will happen if you execute that application; have you tried it?

If you can't understand why it behaves like that, and can't work out how to get it to behave differently, then please ask again.




My Interpretation:




Now my question to the above output is why is it printing
"Welcome to Sydney and (not Welcome to Bangalore)" -- Any Comments Please.?


Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18825
    
  40

Now my question to the above output is why is it printing
"Welcome to Sydney and (not Welcome to Bangalore)" -- Any Comments Please.?



Because the JVM is call the main() method with a particular signature, and the "Welcome to Sydney" one matched that signature.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41809
    
  62
To elaborate on what Henry said, this has nothing to do with overloading - the JVM has hard-coded logic that tells it to call "public static void main (String[])" at application startup.

That's different from calling a method from within Java code (where overloading and type matching rules do apply).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Main() Overloading Vs Main() Overridding