InterviewSolution
Saved Bookmarks
| 1. |
class Transport { var type:String init(type:String) { self.type = type print("Transport - \(type)") } } class Car:Transport { var model:String init(model:String){ super.init(type: "Car") self.model = model self.model = "\(self.model) - type \(self.type)" print("\(self.model)") } } If we try to execute the following what will be the result. Provide reasons let car = Car(model:”Maruti”) |
Answer»
Explanation: employee3 is a struct, and we assign employees2 = employees separate array in MEMORY is CREATED in the memory. And when we add emp3 in employees it is not reflected in employees2. But emp1 and emp2 are REFERENCE types. So if we change employees[0].name = "Sam Smith" employees2[0] is also CHANGED as they REFER to the same object. |
|