wether all void method should have a parameters? | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
0

wether all void method should have a parameters?

6th Nov 2016, 1:35 PM
Edbert andoyo
Edbert andoyo - avatar
3 Respuestas
+ 3
No. Not necessarily. For example, you can have something like: public void heyThere() { System.out.println("Hey there!"); } Which doesn't accept parameters, and it's perfectly fine.
6th Nov 2016, 1:37 PM
Alireza M
Alireza M - avatar
+ 1
You can use void methods as a instructions for object. For example you got a button: button.addActionListener(e -> { changeColorOfButtonToRed();//or whatever you want }); Where method only sets a color of button or anything else and eventually repaints object. It depens if you need to use parameter for method or if this is an inner object method, where you can use the parameters of object.
15th Nov 2016, 9:03 PM
Maksym Zieliński
Maksym Zieliński - avatar
- 3
Void I in place of the return type, and specifies no return value, so it doesn't affect the parameters
8th Nov 2016, 4:45 PM
Cabbage