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

Based on the code snippet provided, analyze the following Swift code and determine the...

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

Based on the code snippet provided, analyze the following Swift code and determine the output:

class PolygonMaker: MakeShape
{
    func makeShape(_ side: Square)
    {
        print("Square of size \(side.s) was created.")
    }
}

let pen = PolygonMaker()
let pencil = Polygon()
pencil.delegate = pen
pencil.makepolygon()

**Expected Output

Choose one option.
Show answer & explanation
Answer: A. A) Square of size 6 was created.

The delegate method receives the Square instance with side modified to 6, printing 'Side of polygon is 6'.

Step-by-step Derivation:
Step 1: makepolygon() sets side.s = 6.
Step 2: Calls delegate?.makeShape(side).
Step 3: PolygonMaker prints 'Side of polygon is 6'.