About Main method in java

Can we overload the main method in java
[46 byte] By [rajnikanthgoldstonea] at [2007-10-3 4:45:48]
# 1

yes we can like this

public class dd {

public static void main(String[] args) {

dd d = new dd();

String[] arr = new String[2];

d.main(arr, "s");

}

public static void main(String[] args,String s) {

// TODO Auto-generated method stub

System.out.println("hi");

}

}

yashyash1234a at 2007-7-14 22:50:09 > top of Java-index,Core,Core APIs...
# 2

Yes but only the main(String[] args) version will be called when you try to run the class as a program.

Or did you mean override? i.e. put a main() method in a class derived from a class which already has one? If so the answer is again yes but if you execute the base class it is the base class's main() method which will be executed (because static methods aren't despatched dynamically like non-static methods).

ejpa at 2007-7-14 22:50:09 > top of Java-index,Core,Core APIs...
# 3
> Or did you mean override? i.e. put a main() method in> a class derived from a class which already has one?> If so the answer is again yes main method is static and static methods cant be overridden
kilyasa at 2007-7-14 22:50:09 > top of Java-index,Core,Core APIs...
# 4
Yes I should have said 'hide'.
ejpa at 2007-7-14 22:50:09 > top of Java-index,Core,Core APIs...
# 5
you mean "redeclared" ?
DurgeshNayaka at 2007-7-14 22:50:09 > top of Java-index,Core,Core APIs...
# 6
No, I meant what I wrote (finally): 'hide'. As it is used in the JLS.
ejpa at 2007-7-14 22:50:09 > top of Java-index,Core,Core APIs...
# 7
> you mean "redeclared" ?A new term?
aniseeda at 2007-7-14 22:50:09 > top of Java-index,Core,Core APIs...
# 8
I mean overload
rajnikanthgoldstonea at 2007-7-14 22:50:09 > top of Java-index,Core,Core APIs...
# 9
Basicaly it is a method forget about main.Only remember public static void main(String []arg){//do}this method implicitly call by jvm.
skmajia at 2007-7-14 22:50:09 > top of Java-index,Core,Core APIs...