Skip to content

Module quiz: Code organization :Advanced Programming in Swift (Meta iOS Developer Professional Certificate) Answers 2026

Question 1

The following class declaration is a base class.

class Vehicle {
}

True
❌ False

Explanation: Ye class kisi aur class se inherit nahi kar rahi, isliye ye base (super) class hai.


Question 2

Given the following code:

class Vehicle {
}
class Truck: Vehicle {
}

Which class is the subclass?

❌ Vehicle
Truck

Explanation: Truck class Vehicle se inherit karti hai, isliye Truck subclass hai.


Question 3

Given the following code in a SecretFood.swift source file:

class SecretFood {
private var secretIngredients: [String] = []
}
class Chef {
func cookSecretFood(_ secretFood: SecretFood) {
print(secretFood.secretIngredients)
}
}

Will the code compile successfully?

Yes
No

Explanation: secretIngredients private hai, isliye Chef class usse access nahi kar sakti.


Question 4

Which option lists the access-level modifiers from least restrictive to most restrictive?

❌ private, fileprivate, internal, public, open
❌ internal, private, fileprivate, public, open
open, public, internal, fileprivate, private

Explanation: Swift access levels ka order openness ke hisaab se hota hai.


Question 5

Which operator guarantees casting will always succeed?

❌ ==
as!
❌ is
❌ as?

Explanation: as! force casting karta hai — agar fail hua to runtime crash hoga, par guarantee karta hai success.


Question 6

Given the following code:

class Spaghetti {
func fetchIngredients() {
print("Spaghetti Ingredients")
}
}
class SpaghettiMeatball: Spaghetti {
override func fetchIngredients() {
print("BBB")
super.fetchIngredients()
print("AAA")

What is the console output?

❌ Spaghetti Ingredients
❌ BBB
❌ AAA

❌ Spaghetti Ingredients

❌ AAA
❌ BBB
❌ Spaghetti Ingredients

BBB
Spaghetti Ingredients
AAA

Explanation: Pehle BBB, fir super.fetchIngredients(), aur end me AAA.


Question 7

Which line is a valid protocol property requirement?

var propertyIdentifier: Int { set }
var propertyIdentifier: Int { get }
let propertyIdentifier: Int

Explanation: Protocol me property ke liye get ya get set likhna zaroori hota hai.


Question 8

Which line is a valid protocol method requirement?

func methodIdentifier() -> String {}
func methodIdentifier() { get }
func methodIdentifier() -> String

Explanation: Protocol me method body nahi hoti.


Question 9

Given the protocol:

protocol Employee {
var daysWorking: Int { get set }
}

Which struct declaration is valid?

var daysWorking: Double
let daysWorking: Int
var daysWorking: Int

Explanation: Type match hona chahiye aur get set ke liye var zaroori hai.


Question 10

How many protocols can a protocol inherit?

❌ 0
❌ 1
Unlimited

Explanation: Swift me protocol multiple protocols inherit kar sakta hai.


Question 11

Which block declares methodIdentifier as an optional requirement?

❌ First
❌ Second
❌ Third
Fourth

@objc protocol ProtocolIdentifier {
@objc optional func methodIdentifier(parameter: Int) -> Int
var propertyIdentifier: Int? { get }
}

Explanation: Optional requirements ke liye @objc + optional required hota hai.


Question 12

Given the following code (incomplete conformance):

What is the console output?

❌ Driver name: Elisa
No delivery driver found.

Explanation: Class DeliveryDriver protocol Driver ko fully conform nahi karti (method missing).


Question 13

Both a struct and a class can adopt protocols.

True
❌ False

Explanation: Swift me structs aur classes dono protocols adopt kar sakte hain.


🧾 Summary Table

Question Correct Answer
Q1 True
Q2 Truck
Q3 No
Q4 open → private
Q5 as!
Q6 BBB → Ingredients → AAA
Q7 { get }
Q8 Method without body
Q9 var daysWorking: Int
Q10 Unlimited
Q11 Fourth option
Q12 No delivery driver found
Q13 True