我不能相信,除非有人用手法来解释这一点,否则,让我也给它一枪!
// Design Class
class HumanClass {
var name:String
init(name:String) {
self.name = name
}
}
var humanClassObject1 = HumanClass(name: "Rehan")
现在左边,即:“人类目标1”是物体,右边,即:人类地图(名称:“Rehan”)就是这个物体。
var humanClassObject2 = HumanClass(name: "Ahmad") // again object on left and it s instance on the right.
因此,举例来说,该物体和物体的具体价值包含(在运行时间)的记忆位置。
Remember the famous statement "object reference not set to an instance of an object", this means that non-initialised objects don t have any instance.
In some programming languages like swift the compiler will not allow you to even design a class that don t have any way to initialise all it s members (variable eg: name, age e.t.c), but in some language you are allowed to do this:
// Design Class
class HumanClass {
var name:String // See we don t have any way to initialise name property.
}
只有当你试图做这样的事情时,才会出现错误:
var myClass = HumanClass()
print(myClass.name) // will give, object reference not set to an instance of the object.
This error indicates that, the specific values (for variablesproperty) is the "INSTANCE" as i tried to explain this above!
And the object i.e: "myClass" contains the memory location (at run-time).