Section 3 :Principles of OOP, The concept of the object, Concept of class,encapsulation,visibility, and information hiding Flashcards
(19 cards)
What is the main aim of Object-Oriented Programming (OOP)?
The main aim of OOP is to bind together the data and the functions that operate on that data, so that no other part of the code can access the data directly except through those functions.
This promotes data security, encapsulation, and modularity.
What is an object in Object-Oriented Programming, and how do objects interact?
- An object is an identifiable entity with characteristics (data) and behavior (functions).
- An object is an instance of a class.
- No memory is allocated when a class is defined, but memory is allocated when an object is created/instantiated.
- During program execution, objects interact by sending messages (method calls) to one another.
- Each object contains its own data and code, and can interact with others without knowing their internal details — only the type of message and response matter.
How do objects interact in Object-Oriented Programming?
Objects interact without needing to know each other’s internal data or implementation.
They only need to know:
What message to send (which method to call)
What kind of response to expect (return type or result)
This allows for abstraction, encapsulation, and modularity in code.
What is a class in C++?
A class is a user-defined data type that acts as a blueprint for objects.
It groups data members (variables) and member functions (methods) that define the properties and behavior of the objects.
What is the difference between a class and an object?
A class is a blueprint — no memory is allocated until used.
An object is an instance of the class — it holds actual data and uses memory.
What are the main components of a class?
Data members – variables to store data
Member functions – functions to operate on that data
Together, they define the state and behavior of objects.
What are the two common ways to define a class in C++?
Inline – Everything is defined within the class body (header only).
Header + Implementation
.h file – class definition (declarations only)
.cpp file – contains the function definitions
Why is a class important in C++?
It enables encapsulation, abstraction, code reusability, and is the foundation of object-oriented programming (OOP).
When is memory allocated to a class?
Memory is only allocated when an object is created, not when the class is defined.
How do objects behave in a program?
Objects interact by calling each other’s methods (message passing), without needing to know internal details — only the interface.
What does a header + implementation class structure look like?
📁 Person.h:
class Person {
public:
void greet();
};
📁 Person.cpp:
#include “Person.h”
#include <iostream>
void Person::greet() {
std::cout << "Hello!";
}</iostream>
How does a class support abstraction?
By hiding internal implementation details and exposing only what is necessary through a public interface (methods).
What does the :: scope resolution operator do in C++?
The :: operator is used to access a variable or function that belongs to a specific class, namespace, or global scope.
To define a class function outside the class:
int MyClass::myFunction() { … }
To access a global variable when there’s a local variable with the same name:
::x // accesses the global x
To use elements from a namespace:
std::cout
What is encapsulation in C++?
Encapsulation is the process of binding data and functions into one unit (a class), while restricting direct access to some components for safety.
What is data abstraction in C++?
Data abstraction is the concept of hiding internal implementation and showing only the necessary details to the user.
How are encapsulation and abstraction related?
Encapsulation hides the data inside a class, and abstraction hides the complexity — both use access modifiers to control visibility.
What does the public access modifier mean?
Members marked public are accessible from anywhere in the program.
What does the protected access modifier mean?
protected members can be accessed within the class and also by derived (child) classes.