You are on page 1of 5

1. What output will be produced by the code below?

import Foundation
let names = ["Serenity", "Sulaco", "Enterprise",
"Galactica"]

if let last = names.last {


print(last)
}
Chọn đáp án:
A. "Galactica"
B. "Serenity"
C. Optional("Galactica")
D. Optional("Serenity")
E. Nil
F. Nothing will be output
G. This code will compile but crash
H. This code will not compile

2. What output will be produced by the code below?

import Foundation
struct Spaceship {
var name: String {
willSet {
print("I'm called \(newValue)!")
}
}
}
var serenity = Spaceship(name: "Serenity")
serenity.name = "TARDIS"
Đáp án:
A. "I'm called Serenity!"
B. "I'm called Serenity!", "I'm called TARDIS!"
C. "I'm called TARDIS!"
D. Nothing will be output
E. This code will compile but crash
F. This code will not compile

3. What output will be produced by the code below?

import Foundation
let oneMillion = 1_000_000
let oneThousand = oneMillion / 0_1_0_0_0
print(oneThousand)

Chọn Đáp án:


A. 1000
B. 1000000
C. 1_000_000
D. 1_0_0_0
E. 1_0_0_0_0_0_0
F. Nothing will be output
G. This code will compile but crash
H. This code will not compile

4. What output will be produced by the code below?

import Foundation
struct Starship {
var name: String
}

let tardis = Starship(name: "TARDIS")


var enterprise = tardis
enterprise.name = "Enterprise"
print(tardis.name)

Chọn đáp án:


A. ""
B. "Enterprise"
C. "TARDIS"
D. Nil
E. Nothing will be output
F. This code will compile but crash
G. This code will not compile

5. What output will be produced by the code below?

import Foundation
var i = 2

repeat {
i *= i * 2
} while i < 100

print(i)

Chọn đáp án:


A. 128
B. 2
C. 64
D. This is an infinite loop
E. Nothing will be output
F. This code will compile but crash
G. This code will not compile

6. What output will be produced by the code below?

import Foundation
final class Dog {
func bark() {
print("Woof!")
}
}
class Corgi : Dog {
override func bark() {
print("Yip!")
}
}
let muttface = Corgi()
muttface.bark()

Chọn đáp án:


A. "Woof!"
B. "Woof!", "Yip!"
C. "Yip!"
D. "Yip!", "Woof!"
E. Nothing will be output
F. This code will compile but crash
G. This code will not compile

7. What output will be produced by the code below?

import Foundation
var i = 2

do {
print(i)
i *= 2
} while (i < 128)

Đáp án:
A. 2, 4, 8, 16, 32, 64
B. 2, 4, 8, 16, 32, 64, 128
C. 4, 8, 16, 32, 64
D. 4, 8, 16, 32, 64, 128
E. This code will compile but crash
F. This code will not compile

8. When this code is executed, what is the value of myStr?

import Foundation
var myStr: String = "0"
myStr = "shiny"

Chọn đáp án:


A. ""
B. "Nil"
C. "Shiny"
D. Nil
E. This code will compile but crash
F. This code will not compile

9. How many bits are used to store an Int?


A. 16-bit
B. 32-bit
C. 64-bit
D. It depends on the device

10. What output will be produced by the code below?

import Foundation
let names = ["Chris", "Joe", "Doug", "Jordan"]

if let name = names[1] {


print("Brought to you by \(name)")
}

Chọn đáp án:


A. "Brought to you by Chris"
B. "Brought to you by Joe"
C. This code will compile but crash
D. This code will not compile

You might also like