Skip to content · ⁨ข้ามไปยังเนื้อหา⁩

Encapsulation: private fields, getters, setters · ⁨Encapsulation: ฟیلด์แบบ private, getters, setters⁩

English

Protect your data

  • Encapsulation means hiding an object's data and only changing it through methods.
  • This keeps the data safe. Other code cannot put a bad value into it.
  • The main tools are the words private and public.

ไทย

ปกป้องข้อมูลของคุณ

  • Encapsulation หมายความว่าซ่อนข้อมูลของ object และแก้ไขผ่าน metMethod เท่านั้น
  • สิ่งนี้ทำให้ข้อมูลปลอดภัย โค้ดอื่นไม่สามารถใส่ค่าที่ไม่ถูกต้องเข้าไปในนั้นได้
  • เครื่องมือหลักคือคำว่า private และ public

ฟิลด์ balance แบบ private เข้าถึงได้เฉพาะผ่าน getBalance และ setBalance

Handout · ⁨เอกสารประกอบการเรียน⁩

Log in or create account · ⁨เข้าสู่ระบบหรือสร้างบัญชี⁩

IGCSE, A-Level & AP