0
wether all void method should have a parameters?
3 Answers
+ 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.
+ 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.
- 3
Void I in place of the return type, and specifies no return value, so it doesn't affect the parameters