Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Compile and Execute Swift Online

import UIKit
// Class
// acess modifires
// 1-private
// 2-public
// 3-internal

class student
{
    private var name:String
    private var sal:Float
     var id:Int
    
    init(name:String,sal:Float,id:Int)
    {
     self.id = id
     self.sal=sal
     self.name=name
    }
    func setName(name:String)
    {
     self.name=name
    }
    func getName()->String
    {
      return self.name
    }
    func setSal(sal:Float)
    {
        if sal>0
        {
         self.sal = sal
        }
        else
        {
          print("please enter logical value")
        }
    }
    func getSal()->Float
    {
      return self.sal
    }
    
}
var s = student(name: "mahmoud", sal: 3000, id: 1)
s.setSal(sal: -4000)
print(s.getSal())

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.