OOP Flashcards
(66 cards)
What is the general nature of an object?
An object encapsulates data (state) and behavior (methods), with its own identity and is created from a class.
What is an abstract entity?
A generalized concept (like an abstract class or interface) that cannot be instantiated, and is used to define structure or behavior that other concrete classes must implement.
eg. “animal” is an abstract entity. You don’t see animals around, you see dogs, birds, cats, etc.
What is the difference between an object and an instantiation?
Instantiation is the process of creating an object from a class. An object is the result of that process—an actual instance of the class with its own state and behavior.
What is instantiation?
The process of creating an object from a class by calling its constructor, which allocates memory and initializes its attributes.
Example: Car myCar = new Car();
What is a UML (unified modelling language) diagram?
A standardized visual representation of a system’s classes, objects, and their relationships, used to model object-oriented programs.
What is the process of decomposition into several related objects?
It’s the process of dividing a complex problem or system into simpler, connected objects, where each object handles its own specific task.
What is dependency (‘uses’) in object-oriented programming?
A relationship where one class depends on another to function, typically by calling its methods or using its data temporarily.
What is aggregation (‘has a’)?
A relationship where one class contains or is composed of other classes, but those parts can exist independently of the whole.
What is inheritance (‘is a’)?
A mechanism where one class (subclass) inherits attributes and methods from another class (superclass), allowing code reuse and hierarchical relationships.
Why is it important to reduce dependencies in a given problem?
Dependencies increase maintenance overheads.
Why is it necessary to have different data types?
To accurately and efficiently represent and manipulate different kinds of data in a program. Each type defines the kind of values a variable can store, how much memory it uses, and what operations can be performed on it.
What is an integer?
A data type used to store whole numbers, both positive and negative, without decimals.
What is a real data type?
A data type used to store numbers with decimal (fractional) parts, including both positive and negative values.
What is a string?
A data type used to store a sequence of characters, such as letters, numbers, and symbols.
What is a boolean?
A data type that can store only two possible values: true or false.
What are parameters in programming?
Parameters are placeholders used in sub-programs (like procedures or functions) to receive data (input) from the part of the program that calls them.
How are data items passed to and from parameters?
Pass by value
When you pass a variable to a method, a copy of the value is passed — not the original.
So if you change it inside the method, the original doesn’t change.
🧠 Example: If you pass x = 5 to a function and the function changes it to 10, x is still 5 outside the function.
(There is another method called pass-by-reference but you don’t need to understand this)
What is encapsulation?
The concept of bundling data and methods that operate on that data into a single class, and restricting direct access to some components using access modifiers (e.g. private, public).
What is polymorphism?
Polymorphism allows objects of different classes to be treated as if they are of the same class, usually through shared methods.
What is method overloading?
Defining multiple methods with the same name but different parameters within the same class.
What is method overriding?
When a subclass provides a new implementation of a method inherited from its superclass, using the same method name and parameters.
What are the advantages of encapsulation?
The scope of data should be confined to the object in which it is defined as far as possible in order to limit side effects and dependencies
Keeps data protected from unauthorized access or accidental changes and improves code maintainability by controlling how data is accessed and modified.
What are the advantages of inheritance?
A parent object holds common data and actions, which enhances reuse and reduces maintenance overheads.
Promotes code reuse by allowing new classes to use existing class functionality and simplifies updates: changes in the parent class automatically affect child classes.
What are the advantages of polymorphism?
An action in a child object may choose to override actions of a parent object. This allows an external program to use the same action on a family of objects without knowing the implementation detail.
Improves flexibility and extensibility of code and enables generic code that works on objects of different types.