Đối tượng: Các实例 của Lớp
Đã giới thiệu| English | Ý nghĩa |
|---|---|
| class/klæs/ | Lớp |
| object/ˈɒbdʒekt/ | Đối tượng |
| blueprint/ˈbluːprɪnt/ | Bản thiết kế |
| instance/ˈɪnstəns/ | Thực thể (instance) |
Classes and objects
- A class 类 is a blueprint 蓝图 — it describes what a kind of thing has and can do.
- An object 对象 is a concrete instance 实例 built from that blueprint.
- One
Stringclass; many String objects ("cat","dog","Ada"). - The class defines the pattern; each object is one filled-in copy.
Blueprint vs. instance
- Think cookie cutter (class) vs. cookies (objects).
- The cutter shapes them; each cookie is a separate, real thing.
- Every object has its own data, even though they share the class's design.
- Changing one object doesn't change the others.

A class diagram: private attributes and public methods
State and behavior
- An object bundles state (its data — instance variables) and behavior (its methods).
- A
Stringobject's state is its characters; its behavior includeslength(),substring(). - You interact with an object by calling its methods.
- This bundling of data + methods is the heart of object-oriented programming.
Lớp hay đối tượng?
Một lớp là bản thiết kế; một đối tượng là một实例 cụ thể. Phân loại từng cái.
Objects have reference types
- An object is stored via a reference — the variable holds its address, not the object.
String s = "hi";—srefers to a String object somewhere in memory.- Two references can point to the same object.
- Reference types behave differently from primitives — a theme of the next lessons.
A class is a type/blueprint; an object is one instance of it — don't conflate them. String is the class; "cat" is an object. Each object carries its own state, so two String objects are independent. And an object variable holds a reference (an address), not the object's bytes directly — this matters when you copy or compare them later.
The class/object relationship:
- Class:
String(the blueprint — every String can dolength(),substring(), …). - Objects:
"cat","dog"— two separate instances, each with its own characters. "cat".length()is3;"dog".length()is3— same behavior, independent state.
A class is a blueprint describing state (instance variables) and behavior (methods); an object is a concrete instance of a class. Many objects can share one class's design while each holds its own state. Objects are reference types — a variable stores the object's address, not the object itself.
Mối quan hệ giữa một lớp và một đối tượng giống như...
Độ khó 1/5 · 100 xu + một phần thưởng nhỏ cho lần hoàn thành đầu tiên trong ngày
Một lớp là bản thiết kế; một đối tượng là một实例 được xây dựng từ nó.
Một đối tượng cụ thể được xây dựng từ một lớp được gọi là ___ của lớp đó (một từ).
Độ khó 1/5 · 100 xu + một phần thưởng nhỏ cho lần hoàn thành đầu tiên trong ngày
Các đối tượng là các实例 của một lớp.
Hai đối tượng của cùng một lớp đều có trạng thái độc lập riêng.
Độ khó 1/5 · 100 xu + một phần thưởng nhỏ cho lần hoàn thành đầu tiên trong ngày
Chúng chia sẻ thiết kế nhưng lưu trữ dữ liệu riêng biệt.
Biến đối tượng thực tế chứa...
Độ khó 1/5 · 100 xu + một phần thưởng nhỏ cho lần hoàn thành đầu tiên trong ngày
Đối tượng là kiểu tham chiếu — biến chứa một địa chỉ.
Trong 'String s = "cat";', String là ___ và "cat" là ___.
Độ khó 1/5 · 100 xu + một phần thưởng nhỏ cho lần hoàn thành đầu tiên trong ngày
String là lớp (bản thiết kế); "cat" là một đối tượng (instance).