Dmytro Antonchenko
Dmytro Antonchenko

Reputation: 326

Final class with class and static funcs

I have two question regarding code below:

final class God {

    class func eat() {
         print("Om nom nom")
    }

    static func throwLightning() {
         print("Zzap")
    }
}
  1. Is it possible to override eat() method without removing final keyword from God class?
  2. Is there any difference between class and static funcs in classes marked as final ?

UPDATE:

Is there any difference from method dispatch point of view?

Upvotes: 0

Views: 57

Answers (1)

matt
matt

Reputation: 535316

Is it possible to override eat() method without removing final keyword from God class?

No. "override" is something you do in a subclass. But final means there can be no subclasses, so where would this "override" even occur?

Is there any difference between class and static funcs in classes marked as final?

No, not from a Swift programmer's point of view. static means class final. But this class is already final, so saying static adds nothing.

Upvotes: 1

Related Questions