Объекты: экземпляры классов
Введено| English | Значение |
|---|---|
| class/klæs/ | класс |
| object/ˈɒbdʒekt/ | объект |
| blueprint/ˈbluːprɪnt/ | чертёж (прототип) |
| instance/ˈɪnstəns/ | экземпляр |
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.
Класс или объект?
Класс — это чертеж; объект — конкретный экземпляр. Распределите каждое.
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.
Связь между классом и объектом похожа на...
Сложность 1/5 · 100 монет + небольшой бонус за первое выполнение сегодня
Класс — это чертеж; объект — экземпляр, построенный из него.
Конкретный объект, созданный из класса, называется ___ этого класса (одно слово).
Сложность 1/5 · 100 монет + небольшой бонус за первое выполнение сегодня
Объекты являются экземплярами класса.
Два объекта одного класса имеют собственное независимое состояние.
Сложность 1/5 · 100 монет + небольшой бонус за первое выполнение сегодня
Они разделяют дизайн, но хранят отдельные данные.
Переменная объекта на самом деле хранит...
Сложность 1/5 · 100 монет + небольшой бонус за первое выполнение сегодня
Объекты — ссылочные типы — переменная содержит адрес.
В 'String s = "cat";', String — это ___, а "cat" — это ___.
Сложность 1/5 · 100 монет + небольшой бонус за первое выполнение сегодня
String — это класс (чертеж); "cat" — это объект (экземпляр).