OA. free
Free
Sirionlabs, Inc Core Computer Science Core Computer Science Medium

Which of the following options correctly denotes the output of the following Swift code...

Sirionlabs, Inc technical mcq question, verified with a worked answer. Free to practise - no sign-up.

Which of the following options correctly denotes the output of the following Swift code snippet?

struct Toy {
    var height: Int = 12
}

protocol ToyShopDelegate {
    func toyWasMade(_ toy: Toy)
}

class ToyShop {
    var delegate: ToyShopDelegate?
    
    func makeToy() {
        let toy = Toy()
        delegate?.toyWasMade(toy)
    }
}

class ToyManu: ToyShopDelegate {
    func toyWasMade(_ toy: Toy) {
        print("Toy made with height \(toy.height)")
    }
}

let shop = ToyShop()
let manu = ToyManu()
shop.delegate = manu
shop.makeToy()
Choose one option.
Show answer & explanation
Answer: A. Toy made with height 12

Accurate technical and quantitative evaluation based on foundational principles.

Step-by-step Derivation:
Step 1: Formulate problem conditions.
Step 2: Apply logical deduction.
Step 3: Conclude correct option.