Can main method overloaded

Can main method overloaded

Answer: Yes you can overload main method and it will work as just general method only one main method public static void main(String args[]) java will match when you try to run the program as an entry point. Please see example below: 

package com.javahonk;

public class MainMethodTest {

	public static void main(String[] args) {
		System.out.println("main(String[] args)");
	}

	public static void main(String arg1) {
		System.out.println("main(String arg1)");
	}

	public static void main(String arg1, String arg2) {
		System.out.println("main(String arg1, String arg2)");
	}

}

 

Output:

Can main method overloaded

Leave a Reply

Your email address will not be published. Required fields are marked *