aspose file tools*
The moose likes Beginning Java and the fly likes main method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "main method" Watch "main method" New topic
Author

main method

Anu satya
Ranch Hand

Joined: Mar 17, 2005
Posts: 146
Hi,
Can any one please let me know ...

Can main method overloaded or overriden?

This is an interview question...


Please help.
Anu


With Regards,
Anu
pankaj vijay
Ranch Hand

Joined: Apr 01, 2008
Posts: 75
Yes it can be overloaded & overridden
check this Example:


Pankaj Vijay (SCJP, SCBCD)
Learn Core Java,Learn Servlet Jsp, SCJP Questions,Struts Tutorial
Karan Johar
Greenhorn

Joined: Oct 02, 2009
Posts: 25
If you overload, then it is no longer the usual main method (i.e it cannot be invoked automatically by jvm)

it can be both overridden and overloaded.
Anu satya
Ranch Hand

Joined: Mar 17, 2005
Posts: 146
Karan Johar wrote:If you overload, then it is no longer the usual main method (i.e it cannot be invoked automatically by jvm)

it can be both overridden and overloaded.


then, is it possible to write like this...will the code compile without any error??

Rahul P Kumar
Ranch Hand

Joined: Sep 26, 2009
Posts: 188
yeas it compiles. But can not be run as main method.
Anu satya
Ranch Hand

Joined: Mar 17, 2005
Posts: 146
ok.

Thanks Rahul, karan and Pankaj.

Regards,
Anu
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13869
    
  10

The normal public static void main(String[] args) method cannot be overridden, because it is a static method, and you cannot override static methods.

See http://faq.javaranch.com/view?OverridingVsHiding
and http://geekexplains.blogspot.com/2008/06/can-you-override-static-methods-in-java.html


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Rahul P Kumar
Ranch Hand

Joined: Sep 26, 2009
Posts: 188
Jesper is right, in some other topic, I've answered that in case of same signature static methods, it is not called overriding, it is called hiding and call to it is decided by the type off reference variable and not by the type of object instantiated.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: main method
 
Similar Threads
why main() is static ?
please reply rahul......
Can a main() method of class be invoked in another class
Symbol Not Found - What am I Missing?
importance of main method in servlets