how important is it to write "void" if you do not want your class to return anything? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

how important is it to write "void" if you do not want your class to return anything?

16th Aug 2016, 12:09 PM
Rayen Ochi
Rayen Ochi - avatar
5 Answers
+ 6
So important, that if you don't, you'll get an error :) By the way, it's void for methods not classes. You don't use void on a class.
16th Aug 2016, 1:48 PM
James
James - avatar
+ 1
If you are referring to the main method in a class (public static void main (String [] args)) then if not entered then the class will not run statements like: System.out.println(); and will not print anything to the console.
16th Aug 2016, 2:02 PM
Divjot Bedi
0
Certainly that would be a error.But remember that constructors don't return anything not even void.
18th Aug 2016, 5:16 AM
Akash Jaiswal
Akash Jaiswal - avatar
0
you need to specify that what type of class you are usimg
21st Aug 2016, 5:11 PM
Hitesh Wedwani
0
it said earlier void for the class that u ain't want any return value. so if you don't declare it, probably an error
15th Sep 2016, 12:13 PM
Hatsune Meepo
Hatsune Meepo - avatar