1.

We want to test cover the function of physicsBooks.  Test the logic if it identifies the physics books from different data sets. Redesign this classes to test cover the method.

Answer»

There will be a compilation error. The derived class Car calls the init method of superclass before its stored property, model gets INITIALISED. Swift does 2 phase initialization, in first phase memory is ALLOCATED and all stored properties get initialized starting from the derived classes and then its superclass. Then in the second phase, all customizations of the properties are done, in the init method.

The correct code will be :

class Car:TRANSPORT {     VAR model:STRING     init(model:String){         self.model = model         super.init(type: "Car")          self.model = "\(self.model) - type \(self.type)"         print("\(self.model)")     } } The result will be   Transport - Car    Maruti  - type Car


Discussion

No Comment Found

Related InterviewSolutions