Swift Tutorial - Tutorialspoint

(backadmin) #1

The ability to take than more form is defined as Inheritance. Generally a class can inherit
methods, properties and functionalities from another class. Classes can be further
categorized in to sub class and super class.


 Sub Class: when a class inherits properties, methods and functions from another
class it is called as sub class

 Super Class: Class containing properties, methods and functions to inherit other
classes from itself is called as a super class

Swift classes contain superclass which calls and access methods, properties, functions and
overriding methods. Also, property observers are also used to add a property and modify
the stored or computed property methods.


Base Class


A Class that does not inherit methods, properties or functions from another class is called
as 'Base Class'.


class StudDetails {
var stname: String!
var mark1: Int!
var mark2: Int!
var mark3: Int!
init(stname: String, mark1: Int, mark2: Int, mark3: Int) {
self.stname = stname
self.mark1 = mark1
self.mark2 = mark2
self.mark3 = mark3
}
}
let stname = "swift"
let mark1 = 98
let mark2 = 89
let mark3 = 76

println(stname)
println(mark1)

24. SWIFT – INHERITANCE

Free download pdf