📢 Too many exams? Don’t know which one suits you best? Book Your Free Expert 👉 call Now!


    Question

    In a program that manages a collection of `Employee`

    objects, each with a `salary` attribute, which control flow mechanism would be most efficient to find all employees whose salary is above a certain threshold? 
    A A `goto` statement to jump to a specific code block. Correct Answer Incorrect Answer
    B An `if-else if-else` ladder for each possible salary range. Correct Answer Incorrect Answer
    C A loop iterating through the collection, using an `if` statement to check the salary condition. Correct Answer Incorrect Answer
    D Recursion to traverse the employee list. Correct Answer Incorrect Answer

    Solution

    This is the most straightforward and efficient way to filter elements in a collection based on a condition. Iterating and applying a conditional check (`if`) allows you to select only the desired elements.

    Practice Next
    ask-question