I don't quite understand methods without return values or arguments.
Please give me an easy-to-understand explanation that even junior high school students can understand, including specific examples.
java
Method of returning the circumference (no arguments)
double getpi()
{
return 3.1415;
}
Method to Print (No Return Value)
void puri (string p)
{
System.out.println(p);
}
Something like that.
In object-oriented programming languages, including Java, an object has a state (information), but such methods may appear when setting/changing this state (information) or inquiring about it.
When the clock object has alarm time information,
A typical implementation in the case is to use a method with no return value that takes the alarm time for the argument.
A typical implementation of the would be a method with no arguments.
class Clock {
LocalTime alarm;
// method with no return value
// set the alarm time
void setAlarm (LocalTime alarm) {this.alarm=alarm;}
// method without arguments
// inquire about the alarm time
LocalTime getAlarm() {return alarm;}
}
© 2024 OneMinuteCode. All rights reserved.