Page 141

Swift

init() { super.init(stm1: 93, results: 89) } }

let marksobtained = display() marksobtained.print() When we run the above program using playground, we get the following result: Mark1:93, Mark2:89 Class 'StudDetails' is defined as super class where student marks are declared and the subclass 'display' is used to inherit the marks from its super class. Sub class defines students marks and calls the print() method to display the students mark.

Overriding Accessing the super class instance, type methods, instance, type properties and subscripts subclass provides the concept of overriding. 'override' keyword is used to override the methods declared in the superclass.

Access to Super class Methods, Properties and Subscripts 'super' keyword is used as a prefix to access the methods, properties and subscripts declared in the super class. Overriding

Access to methods,properties and subscripts

Methods

super.somemethod()

Properties

super.someProperty()

Subscripts

super[someIndex]

Methods Overriding Inherited instance and type methods can be overridden by the 'override' keyword to our methods defined in our subclass. Here print() is overridden in subclass to access the type property mentioned in the super class print(). Also new instance of cricket() super class is created as 'cricinstance'. class cricket { func print() { println("Welcome to Swift Super Class") 129

​Quick is really a powerful and intuitive programming language for macOS, iOS, watchOS and tvO...  

...

Read more
Read more
Similar to
Popular now
Just for you