What is a class in object-oriented programming?
A class is a programmer-defined type that specifies the structure and behavior its objects will have.
Study 2 Classes and Objects with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.
What is a class in object-oriented programming?
A class is a programmer-defined type that specifies the structure and behavior its objects will have.
What is an object, or instance?
An object is a concrete runtime value created from a class; it is also called an instance of that class.
What does instantiation mean?
Instantiation is the process of creating an object from a class.
What is an attribute?
An attribute is a named value associated with a class or object, such as `checking.balance`.
What does an object's state describe?
An object's state is the collection of its attribute values at a particular moment.
What is a method?
A method is a function associated with a class that defines an operation an object can perform or have performed on its behalf.
What is the role of `self` in a Python instance method?
In Python, an instance method conventionally receives the instance as its first parameter, usually named `self`; Python supplies it automatically for an object call.
How do class and instance attributes differ?
A class attribute is shared by a class or its instances, while an instance attribute belongs to one particular object.
Why can mutable class attributes be dangerous?
A mutable class attribute, such as a list or dictionary, is shared, so a change through one instance can be visible through other instances.
What does Python's `__init__()` do?
In Python, `__init__()` is an initializer called automatically after a new instance is created to establish its initial state.
What identifies a Java constructor?
A Java constructor has the same name as its class and has no return type; it is invoked during object creation.
How do object identity and equality differ?
Identity asks whether two references designate the exact same object; equality asks whether their values compare as equal.