Skip to main content

Practice Code Structure

Section 1.22 Identification

Activity 1.22.1.

    These code blocks are the ones you saw in the previous question and they all have the same functionality. Among these options which one is preferable?
  • 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;
    }
    
  • This code can be improved!
  • public static boolean hasPermission(boolean isAdmin, boolean hasWriteAccess, boolean isAccountActive) {
      return isAdmin == true || hasWriteAccess == true || 
                isAccountActive ==true; 
    }
    
  • Still can be improved!
  • public static boolean hasPermission(boolean isAdmin, boolean hasWriteAccess, boolean isAccountActive) {
      return isAdmin || hasWriteAccess || isAccountActive; 
    }
    
  • Correct!
You have attempted 1 of 2 activities on this page.