Can We Overload main() method in Java?
Yes, by method overloading. You can have any number of main
methods in a class by method overloading. But JVM calls a main() method which
receives string array as arguments only. Let's see the simple example:
public class OverloadExample {
|
public static void main(String[] args) {
|
System.out.println("main with
String[]");
|
}
|
public static void main(String args) {
|
System.out.println("main with
String");
|
}
|
public static void main() {
|
System.out.println("main
without args");
|
}
|
}
|
Output:
main with String[]
No comments:
Post a Comment