Question: Suppose we created a class in Swift called Point, with properties x and y , and the usual initializer. Is there any way that we

Suppose we created a class in Swift called Point, with properties x and y, and the usual initializer. Is there any way that we could follow the declaration
let p = Point(1,2)
with
p.x =5
No, because the declaration is wrong. The new operator is missing.
Yes, as long as the property x is computed, rather than stored.
No, properties are private by default in Swift.
No, let-constants make the instances they refer to immutable. We would have to change let to var to make the instance mutable.
Yes, the let only means we can't change what p is bound to, but we may still be able to mutate the properties of the instance.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!