2020-11-18-类的属性
作者:
清风明月伴我行 | 来源:发表于
2020-11-18 19:06 被阅读0次
类
import UIKit
class Student {
var name : String?
var age : Int = 0
var chineseScore : Double = 0
var mathScore : Double = 0
//计算属性 : 通过别的方式计算到结果的属性,称之为计算属性
var averageScore: Double {
return (chineseScore + mathScore) * 0.5
}
//类属性:是和整个类相关的属性,而且是通过类名进行访问
static var courseCount : Int = 0
}
var stu = Student()
//给对象的属性赋值
stu.name = "mark"
stu.age = 18
stu.mathScore = 44.0
stu.chineseScore = 89.00
//给类属性赋值
Student.courseCount = 2
if let name = stu.name {
print(name)
}
stu.averageScore
本文标题:2020-11-18-类的属性
本文链接:https://www.haomeiwen.com/subject/lrsciktx.html
网友评论