IOS Mobile Application Development
Session 16 Swift IOS Code
//// Encapsulation
class Maths
{
let a: Int!
let b: Int!
private var result: Int?
init(a: Int, b: Int)
{
self.a = a
self.b = b
}
func add()
{
result = a + b
}
func sumresult()
{
print("The sum is: \(result)")
}
}
let cal = Maths(a: 3, b: 2)
cal.add()
cal.sumresult()
class abc
{
private var x: Int = 0
public var z:Int
{
get
{
return x * 4
}
set
{
x = newValue
}
}
}
let cal1 = abc()
cal1.z = 2
print(cal1.z)
class def
{
static var fs = "Hi Everyone from Fahad Hussain CS"
var name : String = "Fahad"
var age : Int = 1
}
print(def.fs)
print(def.name)
No comments:
Post a Comment
Fell free to write your query in comment. Your Comments will be fully encouraged.