Quiz: Foundations of Object-Oriented Programming — 18 questions

Detailed questions and answers

1. What is the primary purpose of a programming language?

To write instructions that tell a computer how to perform tasks
To measure the electrical capacity of a computer processor
To translate spoken conversations into natural human languages
To organize hardware components into physical computer systems

To write instructions that tell a computer how to perform tasks

Explanation

A programming language is used to write instructions that direct a computer to perform specific tasks. Organizing hardware, translating conversations, and measuring processor capacity are different functions.

2. Which sequence best illustrates procedural programming when making tea?

Store the ingredients as data while allowing functions to operate on them freely
Serve the tea, then decide whether to boil water based on its flavor
Boil water, add tea powder, add milk, add sugar, and serve
Create separate tea objects that independently control water and serving

Boil water, add tea powder, add milk, add sugar, and serve

Explanation

Procedural programming represents a task as an ordered sequence of steps, such as boiling water before adding ingredients and serving. The other choices describe nonsequential or object-centered approaches rather than a direct top-to-bottom procedure.

3. Which combination identifies major limitations of procedural programming in large software systems?

Flexible inheritance, controlled access, abstraction, and reduced code duplication
Clear object boundaries, reusable classes, hidden implementation details, and encapsulation
Poor reusability, difficult maintenance, dependent code, and weak data security
Automatic reuse, independent modules, strong data security, and simple maintenance

Poor reusability, difficult maintenance, dependent code, and weak data security

Explanation

Procedural programming can suffer from poor code reuse, dependent code, weak data security, and difficult maintenance as programs become large. The other choices describe advantages or mechanisms associated with object-oriented programming.

4. Why can error checking become difficult in a large procedural program?

Access control prevents functions from sharing data with related operations
Dependencies among procedures can make changes and faults spread across the program
Classes automatically hide implementation details from every procedure
Inheritance creates reusable methods that can be checked at several levels

Dependencies among procedures can make changes and faults spread across the program

Explanation

Large procedural programs may contain dependent code, so a change or fault in one procedure can affect other parts and complicate error checking. Classes, inheritance, and access control are object-oriented mechanisms rather than explanations of this procedural limitation.

5. What distinguishes object-oriented programming from procedural programming?

It focuses on executing one fixed series of steps to represent a real-world entity
It arranges instructions as a top-to-bottom sequence of independent procedures
It keeps data separate from the functions that process it in every design
It combines data and the functions operating on that data within objects

It combines data and the functions operating on that data within objects

Explanation

Object-oriented programming combines data and related methods within objects that can represent real-world entities. A top-to-bottom sequence and separate data and functions characterize procedural programming instead.

6. A software team wants to reuse common features, restrict direct data access, and hide unnecessary implementation details; which object-oriented mechanisms address these goals?

Top-to-bottom execution, global data flow, and dependent procedures
Manual duplication, exposed implementation, and independent data records
Sequential instructions, separate functions, and unrestricted data sharing
Inheritance, access control, and abstraction or encapsulation

Inheritance, access control, and abstraction or encapsulation

Explanation

Inheritance supports reuse, access control improves security, and abstraction and encapsulation hide details while controlling access. The other combinations describe procedural characteristics or practices that do not provide these object-oriented benefits.

7. What is the primary role of a class in object-oriented programming?

It represents a method call that selects code during execution
It stores one concrete entity with its current attribute values
It provides a blueprint containing data and functions for creating objects
It sends requests between existing objects to perform operations

It provides a blueprint containing data and functions for creating objects

Explanation

A class is a user-defined type and blueprint containing data members and member functions used to create objects. An object, rather than a class, is a concrete instance that occupies memory and holds actual values.

8. Which description best characterizes an object?

A variable declared inside a class to store one value
An identifiable instance of a class with state and behaviour
A logical template that declares attributes and methods
A code block inside a class that performs a specific task

An identifiable instance of a class with state and behaviour

Explanation

An object is an identifiable instance of a class that represents a real-world entity through its state and behaviour. A class defines possible attributes and methods but is not itself the concrete instance.

9. A student's name and marks describe the student's current state, while calculating an average describes what aspect of the object?

Its behaviour, expressed through methods or responses
Its class, which acts as the object's logical blueprint
Its identity, which determines the object's memory location
Its data members, which define the object's available actions

Its behaviour, expressed through methods or responses

Explanation

An object's state is represented by its attributes, whereas its behaviour is represented by methods and responses to other objects. A calculation such as finding an average is an action performed through behaviour.

10. What does encapsulation accomplish in an object-oriented design?

It allows one operation to produce different behaviour in different situations
It displays essential information while concealing implementation details from users
It combines data with the functions operating on it and controls access through methods
It derives a new class from an existing class to reduce repeated code

It combines data with the functions operating on it and controls access through methods

Explanation

Encapsulation wraps data and the functions that operate on it into one unit, with access controlled through the unit's methods. Displaying essential information while hiding implementation details is the role of abstraction.

11. Which distinction correctly separates data abstraction from information hiding?

Abstraction combines data with methods, while information hiding creates subclasses for code reuse
Abstraction gives an operation several forms, while information hiding represents an object's state
Abstraction selects a method at runtime, while information hiding selects it during compilation
Abstraction hides implementation details, while information hiding protects sensitive data from unauthorized access

Abstraction hides implementation details, while information hiding protects sensitive data from unauthorized access

Explanation

Data abstraction presents essential information while concealing implementation details, whereas information hiding protects important or sensitive data from unauthorized access. Bundling data with methods describes encapsulation, not abstraction.

12. A new class reuses the properties and characteristics of an existing class to avoid duplicated code. Which OOP principle is being used?

Encapsulation
Inheritance
Information hiding
Polymorphism

Inheritance

Explanation

Inheritance allows a class to derive properties and characteristics from another class, promoting reuse and reducing duplication. Encapsulation concerns controlled bundling of data and its operating functions.

13. What does polymorphism allow an operation or message to do?

Keep data and its associated functions together inside one controlled unit
Appear in more than one form and produce different behaviour in different situations
Acquire properties and characteristics from a parent class
Reveal essential information while concealing implementation details

Appear in more than one form and produce different behaviour in different situations

Explanation

Polymorphism is the ability of a message or operation to appear in multiple forms and produce different behaviour in different situations. Acquiring characteristics from another class is inheritance.

14. What is binding in object-oriented programming?

Combining an object's data with the functions that operate on it
Sending a request from one object to another to invoke a method
Associating a method call with the actual method or code that will execute
Representing an object's state through its attribute values

Associating a method call with the actual method or code that will execute

Explanation

Binding associates a method call with the actual method or code that will be executed. Sending a request between objects is message passing, which can eventually lead to a method call.

15. When a method call is linked to an implementation at compile time rather than during execution based on the actual object, what kind of binding is used?

Polymorphic binding, based on changing object state
Static binding, also called early binding
Message binding, based on a request between objects
Dynamic binding, also called late binding

Static binding, also called early binding

Explanation

Static or early binding connects a method call to its implementation at compile time. Dynamic or late binding makes that connection at runtime according to the actual object.

16. What happens during message passing between objects?

A compiler connects every method call to its implementation before program execution
A subclass derives properties from a parent class to reduce code duplication
One object sends a request to another object to invoke a method and perform an operation
An object hides its implementation details while exposing essential information

One object sends a request to another object to invoke a method and perform an operation

Explanation

Message passing occurs when one object requests that another object invoke one of its methods to perform an operation. Compile-time method association describes static binding rather than message passing.

17. Which situation best demonstrates code reusability in object-oriented programming?

An object exposes its internal data directly to external procedures
A subclass uses an inherited method instead of rewriting its functionality
A developer changes several unrelated files after every small update
A program stores identical customer records in two separate databases

A subclass uses an inherited method instead of rewriting its functionality

Explanation

Code reusability allows existing functionality to be used again through mechanisms such as inheritance, reusable classes, or methods. Storing duplicate records concerns data redundancy, while changing files concerns maintenance and exposing data conflicts with encapsulation.

18. How does encapsulation contribute to security in object-oriented programming?

It restricts unauthorized or accidental access to an object's data
It requires developers to rewrite dependent code after each modification
It lets every class reuse methods without defining access controls
It copies the same data into multiple storage locations for backup

It restricts unauthorized or accidental access to an object's data

Explanation

Encapsulation and data hiding protect an object's data from unauthorized or accidental access. Data duplication does not provide this protection, and reuse or maintenance addresses different benefits of object-oriented programming.

Review with flashcards

Memorize the answers with 40 flashcards on Foundations of Object-Oriented Programming.

What is a programming language?

A language used to write instructions for a computer.

Name some examples of programming languages.

Python, Java, C, C++, and JavaScript.

What is procedural programming?

A programming approach using a sequence of steps executed top to bottom.

See flashcards →

Read the study sheet

Read the complete study sheet on Foundations of Object-Oriented Programming.

See study sheet →

Similar courses

Create your own quizzes

Import your course and AI generates quizzes with corrections in 30 seconds.

Quiz generator