---
title: "Can we overload main() method?"  
description: "Can we overload main() method?"  
author: "Samuel Fernandes"  
published: 2015-03-30  
updated: 2020-09-18  
canonical: https://www.mindstick.com/interview/2377/can-we-overload-main-method  
category: "java"  
tags: ["java"]  
reading_time: 1 minute  

---

# Can we overload main() method?

Yes, by method overloading. We can have any number of main methods in a class by method overloading. Here is a example:\

```
class Overloading1{
  public static void main(int a){
  System.out.println(a);
  }

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

**Output :** 10

\

## Answers

### Answer by Anonymous User

Yes, by method overloading. We can have any number of main methods in a class by method overloading. Here is a example:\

```
class Overloading1{
  public static void main(int a){
  System.out.println(a);
  }

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

**Output :** 10

\


---

Original Source: https://www.mindstick.com/interview/2377/can-we-overload-main-method

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
