let sa = [
Chemistry(physics: "solid physics", equations: "Hertz"),
Maths(physics: "Fluid Dynamics", formulae: "Giga Hertz")]
let samplechem = Chemistry(physics: "solid physics", equations: "Hertz")
println("Instance physics is: \(samplechem.physics)")
println("Instance equation is: \(samplechem.equations)")
let samplemaths = Maths(physics: "Fluid Dynamics", formulae: "Giga Hertz")
println("Instance physics is: \(samplemaths.physics)")
println("Instance formulae is: \(samplemaths.formulae)")
When we run the above program using playground, we get the following result:
Instance physics is: solid physics
Instance equation is: Hertz
Instance physics is: Fluid Dynamics
Instance formulae is: Giga Hertz
Type Checking
Type checking is done with the 'is' operator. The 'is' type check operator checks whether
the instance belongs to particular subclass type and returns 'true' if it belongs to that
instance else it will return 'false'.
class Subjects {
var physics: String
init(physics: String) {
self.physics = physics
}
}
class Chemistry: Subjects {
var equations: String
init(physics: String, equations: String) {