/*
Swift's inheritance
If you want to override the storage properties of the parent class
1. After rewriting, you can add property observers to it. Column One:
2. You can change it to a calculated attribute (but not the original function of the Parent property). Column two:
3. The parent class is read-only (get, or let), and the subclass cannot add a property observer. Column three:
If you override the computed property of the parent class
1. The parent-Class computed property is read-only and can be overridden by subclasses to add the Seter method. Column four:
Method inheritance. Column Five:
*/
Column One:
Class Person {
var name:string = "CJ"
}
Class Child:person {
Override Var name:string {
Willset {
}
Didset {
}
}
Override var name:string = "CJ" error
}
Column two:
Class Person2 {
var name:string = "CJ"
}
Class Child2:person2 {
Override Var name:string {
get {
Return "Chenhe"
}
set {
}
}
}
Column three:
Class Person3 {
var name:string {
Return "Chenhe"
}
Let Height:int = 12
}
Class Child3:person3 {
Override Var name:string {
Willset {
//
// }
Didset {
//
// }
// }
Override Let Height:int {
Willset {
//
// }
Didset {
//
// }
// }
}
Column four:
Class Person4 {
var name:string {
Return "Chenhe"
}
}
Class Child4:person4 {
Override Var name:string {
get {
Return "Chenhe"
}
set {
}
}
}
Column Five:
Class Person5 {
var name:string {
Return "Chenhe"
}
Func x () {
Print ("Hello")
}
}
Class Child5:person5 {
Override Func X () {
Print ("Good for You")
}
}
Run-time polymorphism
Let a:person5 = Child5 ()
A.x ()
Initialize dry two things, allocate space, assign values to members
The initialization method of structure body
struct Point {
var x:int
var y:int
}
Let p = Point violates the principle of initialization and does not assign a value to a member. One of the following can be listed:
Let p = Point (X:1, Y:2)
struct Point2 {
var x:int = 4
var y:int = 3
}
Let P2 = Point2 ()//This will not give an error, allocate space and assign values to the member
struct POINT3 {
var x:int
var y:int
Write a full constructor to initialize all the members
Init (xx:int,yy:int) {
x = XX
y = yy
}
}
Swift's inheritance and initialization of the struct body