1

Normally we should use keyword class to define a class computed property, like

class Square{
    class var area:Float{
        return 100.0*100.0
    } 
}

However we can not use class to define a stored property (I know it results from OC).

And meanwhile we may use static in a class to define a stored property and it runs successfully.

enter image description here

So my question is: what are the differences between static and class when used in a class?

Blackus
  • 6,883
  • 5
  • 40
  • 51
lwiu
  • 179
  • 1
  • 9

2 Answers2

1

The main difference between static and class is that class elements can be overridden.

As a short way to say this, static has the same effect that final class.

You can refer to this question to have more details.

Community
  • 1
  • 1
Blackus
  • 6,883
  • 5
  • 40
  • 51
0

I would refer to this, basically, you can override a class func/var, but you cannot a static one.

Community
  • 1
  • 1
Dániel Nagy
  • 11,815
  • 9
  • 50
  • 58