ข้ามไปยังเนื้อหา

The this Keyword

แนะนำใหม่
เอกสารประกอบการเรียน
บทเรียนวิดีโอสำหรับหัวข้อนี้ เปิดหน้าวิดีโอ
7:20

การสร้างคลาส

นี่คือนักเรียน ซึ่งจัดเก็บเป็นตัวแปรอิสระสามตัว: ชื่อ, ปีการศึกษา, และเกรด. นั่นทำงานได้ดี.ตอนนี้เพิ่มนักเรียนอีกพันคน. คุณจำเป็นต้องใช้ตัวแปรสามพันตัว…

บรรยายภาษาอังกฤษ · สลับคำบรรยายภาษาอังกฤษและภาษาจีนได้

ในบทเรียนนี้

บทเรียนวิดีโอ
English

A parameter can hide the field it should update

  • An object has name "Ada". setName(String name) runs name = name; with the argument "Bo".
  • Both unqualified names refer to the parameter, so the object still has "Ada". this.name = name assigns the parameter value to the field instead.
A parameter can hide the field it should update: in setName(String name), name = name assigns the parameter to itself, so the object keeps "Ada"; this.name = name assigns the parameter value "Bo" to the field

เอกสารประกอบการเรียน

เข้าสู่ระบบหรือสร้างบัญชี

IGCSE, A-Level & AP