Prepare for the A Level Computer Science OCR Exam with engaging quiz questions and interactive flashcards. Get ready to excel in your exam with comprehensive study materials designed to bolster your knowledge and confidence.

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


In object-oriented programming, what is a class?

  1. A collection of algorithms

  2. A data structure holding attributes and methods

  3. A set of procedures

  4. A stand-alone function

The correct answer is: A data structure holding attributes and methods

A class in object-oriented programming is fundamentally a data structure that encapsulates attributes (also known as properties or fields) and methods (functions or procedures) that define the behavior of the objects created from that class. By grouping these attributes and methods together, a class serves as a blueprint for creating instances or objects that represent specific entities in the program. For example, consider a class called `Car`. This class might have attributes such as `color`, `make`, and `model`, which define the properties of a car object. It could also have methods like `accelerate()` or `brake()`, which define the behaviors associated with a car. Thus, a class allows for the organization of data and functionality in a structured way, promoting code reusability, encapsulation, and abstraction. The other options do not accurately represent the concept of a class in object-oriented programming. A collection of algorithms refers more to a set of instructions or processes, whereas a set of procedures focuses on specific functions without incorporating data representation. A stand-alone function is a single unit of code that performs a task but does not encapsulate attributes or define the behavior of a broader concept like a class does.