Can't I use int main() in java? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

Can't I use int main() in java?

recently I observed using int main() with return 0 shows an error in Java

2nd Dec 2019, 12:57 PM
Aditya
Aditya - avatar
2 Answers
+ 3
in java it has to be void. the return in main() in other programming languages returns a value to check the status of the exit. in java you can use System.exit()
2nd Dec 2019, 1:04 PM
Bahhaⵣ
Bahhaⵣ - avatar
+ 1
Can the main() method in Java return any data? No. main() always has void as its return type. The reason is whenever a method has a return type other than void then the value returned must be stored in a memory location in the invoking method. In Java programs, the point from where the program starts its execution or simply the entry point of Java programs is the main() method. Hence, it is one of the most important methods of Java and having proper understanding of it is very important. class GeeksforGeeks { public static void main(String[] args) { System.out.println("I am a Geek"); } } If you to learn and make career as Java developer then go through here: https://www.cetpainfotech.com/technology/java-training
5th Dec 2019, 5:56 AM
ananya gupta
ananya gupta - avatar