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

objects and classes 1

import Foundation
import Glibc
 
class NamedShape
{
    var name:String
    var sides:Int=0
    init(name:String,sides:Int)
    {
        self.name=name
        self.sides=sides
    }
    
    func simpleDescription()-> String
    {
        return "\(name) has \(sides) sides "
    }
}



class Shape:NamedShape
{
    var Area:Double=0.0
    var len:Double=0
    init(name:String,sides:Int,len:Double)
    {
        self.len=len;
        super.init(name:name,sides:sides)
    }
    
    func area(len:Double)->Double
    {
        Area=len*len
        return Area
    }
    
    func show()-> String
    {
        let a=area(len:len)
        return "\(name) has \(sides) sides with \(a) sq m "
    }
    
}

let shape=Shape(name:"square",sides:4,len:10.2)
let h=shape.show()
print(h)



Advertisements
Loading...

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