K-12 CS Teacher Professional Development Workshop
1.) Does this method compile?
public static void kill(int num) {
marg = num;
return;
marg = num + 5;
}
This method does compile. Void can strictly not return any TYPE, but it methods with the void return type can still use the return command to simply end the method. Thus, marg would also only be set to num, and the last line of code would be ignored.
2.) Does this method compile?
public char number(int num) {
if (boolVar == true) {
return num;
}
else {
return num++;
}
}
This method does not compile because num is an int type and the method needs to return a char type.