1/37
Vocabulary flashcards covering key object-oriented programming concepts from the lecture notes.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Object
A value that combines data and the code that operates on that data; created from a class and represents an instance.
Class
A blueprint describing the data (fields) and behavior (methods) that all objects of that kind have.
Instance
A concrete object created from a class.
Static
A class-level member that belongs to the class itself, not to any specific object; can be accessed without an instance.
Method
A block of code defined in a class (or object) that can be called with parameters to perform actions or return a value.
Parameter
An input variable declared in a method signature; values provided when the method is called.
Return type
The type of value a method returns; use void if the method returns nothing.
void
A return type indicating the method does not return a value.
Public
An access modifier that makes a class, method, or field accessible from other code.
Private
An access modifier that restricts access to within the declaring class.
this
A keyword that refers to the current object inside an instance method.
Constructor
A special method that initializes a new object; has the same name as the class and no return type.
new
Operator that creates a new object and allocates memory for it.
Encapsulation
Bundling data and the code that operates on it inside a class and protecting data from invalid changes.
Abstraction
Hiding complex implementation details behind a simple interface.
Invariant
A rule that must always hold true for an object’s state (e.g., health must be >= 0).
getBalance
An accessor method in BankAccount that returns the current balance.
deposit
A method to add funds to an account; often returns a boolean indicating success.
withdraw
A method to remove funds from an account; may enforce rules and return a boolean.
BankAccount
An example class demonstrating encapsulation with private fields like balance and methods to manage money.
Player
A class used to demonstrate encapsulation; tracks stats like health and gold and provides methods to modify them.
health
A data field representing a Player’s vitality.
gold
A data field representing a Player’s currency.
takeDamage
A method that reduces health by an amount, ensuring health does not go below zero.
heal
A method that increases health by an amount, often guarded to enforce rules.
this.health
Accessing the current object’s health field; demonstrates use of this to disambiguate.
getHealth
Accessor method that returns a Player’s health.
setHealth
Mutator method that assigns a new health value while enforcing constraints like max health.
Area damage (wrong vs. right)
Wrong: pass primitive health values (copies) to modify; Right: pass Player references so the actual objects are modified.
Reference Type
Objects stored as references; copying the reference copies the address, not the object.
Primitive Type
Basic values stored directly (e.g., int, double); copying creates independent copies.
pass-by-value
Java passes a copy of the value; for primitives this is a new value, for references it’s a copy of the reference.
Locker analogy
Primitives are like sticky notes (independent copies); objects are like lockers (shared references).
Constructor invocation steps
new allocates memory, default values are set, constructor runs to initialize, and a reference to the new object is returned.
Encapsulation example (private fields)
Private data cannot be accessed directly; public methods control how data is changed.
Abstraction example
Hide complex logic behind simple method calls like heal or orderCheeseburger.
Polymorphism
Ability to treat different classes (e.g., Player, Monster, Building) the same when applying certain operations (to be explored later).
Inheritance
A mechanism for sharing code by creating a subclass that reuses behavior (to be explored later).