Can main method be overloaded illustrate with an example program




















Multiply two matrices. Find the standard deviation. Reference Materials String. Start Learning Java. Explore Java Examples. Related Topics Java Varargs. Java Command-Line Arguments. Why method overloading? How to perform method overloading in Java? Here are different ways to perform method overloading: 1. Overloading by changing number of arguments Overloading by changing type of arguments Example: Method Overloading Important Points. Here if we try to pass the float numbers to the int return type, it will not accept the argument and will throw an error.

Here the compiler will throw an error because the types of arguments and the number of arguments passed to methods are the same. You can also go through our other suggested articles to learn more —. Submit Next Question. By signing up, you agree to our Terms of Use and Privacy Policy. Forgot Password? This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy.

By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy. Popular Course in this category.

Published in Core Java. Previous Post Why to use Abstract keyword in java language? Next Post C program for area of rectangle. Yes you can Overload main method but in any class there should be only one method with signature public static void main string args[] where your application starts Execution, as we know in any language Execution starts from Main method.

How are we doing? Please help us improve Stack Overflow. Take our short survey. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams?

Collectives on Stack Overflow. Learn more. Can we overload the main method in Java? Ask Question. Asked 11 years, 3 months ago. Active 1 year, 5 months ago. Viewed k times. Can we overload a main method in Java? Improve this question. Manoj Govindan Mohan Mohan 3, 9 9 gold badges 29 29 silver badges 40 40 bronze badges.

Why would you want to overload the main method. You can create as many classes as you like with a main if you want different startup behaviour. Just state the main class when you invoke the jar. Or you could just add some extra arg that you test when your main starts that affects what it does.



0コメント

  • 1000 / 1000