Activity 1.21.1.
hasPermission(true, true, true)
permission(false, false, false)
hasPermission(true, true, false)
hasPermission(true, false, false)
hasPermission(true, false, true)
hasPermission(false, true, true)
public static boolean hasPermission(boolean isAdmin, boolean hasWriteAccess, boolean isAccountActive) { return isAdmin && hasWriteAccess && isAccountActive; }
- Not always! Compare the output of the first code vs. code block in option A for
hasPermission(false, true, true);
public static boolean hasPermission(boolean isAdmin, boolean hasWriteAccess, boolean isAccountActive) { return isAdmin || hasWriteAccess || isAccountActive; }
- Correct!
public static boolean hasPermission(boolean isAdmin, boolean hasWriteAccess, boolean isAccountActive) { return isAdmin == true || hasWriteAccess == true || isAccountActive == true; }
- Correct!
Look at the first code block. Which of the following options have the same functionality as it (i.e., they produce the same output for the same inputs)? You can check the Hint for some input examples.
public static boolean hasPermission(boolean isAdmin, boolean hasWriteAccess, boolean isAccountActive) {
if (isAdmin == true) {
return true;
}
if (hasWriteAccess == true) {
return true;
}
if (isAccountActive == true) {
return true;
}
return false;
}
Hint.
You can use the following test cases to compare the code blocks’ functionality.
Select all that apply.