class Person {
}
let man = Person()
var gender: String!
func play(sport: String) { }
class Maths {
let a, b: Int!
private var result: Int?
init(a: Int, b: Int) {
self.a = a
self.b = b
}
func add(a: Int, b: Int) {
result = a + b
}
func displayResult() {
print("Result - \(result)")
}
}
let maths = Maths
maths.add()
maths.displayResult()
result is encapsulated in the example
Abstraction - expose relavant data and hide internal details.
In the above example, we are hiding internal calculation for add method
.
Method Overriding - Overriding is the process by which two methods have the same method name and parameters. One of the methods is in the parent class and the other is in the child class.