can you change return type of main method ? like int, char or float | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

can you change return type of main method ? like int, char or float

3rd Jan 2017, 2:53 PM
Rohit choudhary
Rohit choudhary - avatar
4 Answers
+ 6
main has nowhere to return data.
3rd Jan 2017, 3:53 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 2
No, the return type of main() method must be void only. If the return type is anything else the compilation will be sucessful. But, you can’t run the java program. You will get run time error as main method not found.
3rd Jan 2017, 3:40 PM
Akash Middinti
+ 2
main mathod return type must be void and it must be declared as static
4th Jan 2017, 2:18 PM
Niloy Rashid
Niloy Rashid - avatar
+ 2
yes, but if we are overloading the main method i.e. class Program{ public static void main(String[] args){ System.out.println(main(5)); //5 } public static int main(int a){ return a; } }
14th Mar 2017, 8:47 AM
NEERAJ CHOUHAN
NEERAJ CHOUHAN - avatar