Question:

What output will be produced by the code below?

final class Dog {
    func bark() {
        print("Woof!")
    }
}

class Corgi : Dog {
    override func bark() {
        print("Yip!")
    }
}

let muttface = Corgi()
muttface.bark()

Answer:

Correct answer: This code will not compile.

Explanation: This code attempts to create a new class, Corgi, that inherits from an existing class, Dog. Ordinarily that would be fine, but here the Dog class has been marked as final, which means it cannot be inherited from.


Keywords:

© 2017 QuizBucket.org