Encapsulation means bundling data and methods that work on that data into one unit, like a class. It hides the internal details and only exposes what is necessary.
Click to reveal answer
beginner
Define Inheritance in simple terms.
Inheritance lets a new class use properties and methods of an existing class. It’s like a child inheriting traits from a parent.
Click to reveal answer
intermediate
What is Polymorphism in OOP?
Polymorphism means one interface can represent different underlying forms (data types). For example, a function can work with different classes through a common interface.
Click to reveal answer
beginner
Explain Abstraction with an example.
Abstraction means showing only the important details and hiding the complex parts. Like driving a car: you use the steering wheel without knowing how the engine works.
Click to reveal answer
beginner
Why are OOP principles useful in programming?
They help organize code better, make it reusable, easier to maintain, and model real-world things clearly.
Click to reveal answer
Which OOP principle hides internal data and only exposes necessary parts?
AEncapsulation
BInheritance
CPolymorphism
DAbstraction
✗ Incorrect
Encapsulation bundles data and methods and hides internal details from outside access.
What does Inheritance allow in OOP?
AHiding complex details
BA class to use properties of another class
CUsing one interface for many forms
DGrouping data and methods
✗ Incorrect
Inheritance lets a new class reuse code from an existing class.
Polymorphism allows:
AGrouping data and functions
BData hiding
CCode reuse by inheritance
DMultiple forms through one interface
✗ Incorrect
Polymorphism means one interface can represent different underlying forms.
Abstraction is best described as:
AHiding data
BReusing code
CShowing only important details
DChanging behavior at runtime
✗ Incorrect
Abstraction hides complex details and shows only what is needed.
Which principle helps organize code to model real-world things?
AOOP principles
BProcedural programming
CFunctional programming
DStructured programming
✗ Incorrect
OOP principles help organize code to represent real-world objects clearly.
Explain the four main OOP principles and give a simple example for each.
Think about how a car works to explain abstraction.
You got /4 concepts.
Why is encapsulation important in programming? How does it help keep code safe and organized?
Imagine a capsule that protects medicine inside.
You got /4 concepts.
Practice
(1/5)
1. Which of the following is NOT one of the four main principles of Object-Oriented Programming (OOP)?
easy
A. Encapsulation
B. Compilation
C. Polymorphism
D. Inheritance
Solution
Step 1: Recall the four main OOP principles
The four main principles are encapsulation, inheritance, polymorphism, and abstraction.
Step 2: Identify the option not in the list
Compilation is a process of converting code, not an OOP principle.
Final Answer:
Compilation -> Option B
Quick Check:
OOP principles exclude compilation [OK]
Hint: Remember the four OOP pillars: E, I, P, A [OK]
Common Mistakes:
Confusing compilation with abstraction
Mixing OOP principles with programming processes
2. Which keyword is used in C++ to create a new class?
easy
A. class
B. struct
C. object
D. define
Solution
Step 1: Identify the C++ keyword for defining a class
In C++, the keyword to define a class is class.
Step 2: Check other options
struct defines a structure, object is not a keyword, and define is for macros.
Final Answer:
class -> Option A
Quick Check:
Use class to define classes [OK]
Hint: Use 'class' keyword to define classes in C++ [OK]
Common Mistakes:
Confusing struct with class
Using 'object' as a keyword
Mixing macros with class definition
3. What will be the output of the following C++ code?
class Animal {
public:
void sound() { std::cout << "Animal sound"; }
};
class Dog : public Animal {
public:
void sound() { std::cout << "Bark"; }
};
int main() {
Animal* a = new Dog();
a->sound();
delete a;
return 0;
}
medium
A. Runtime error
B. Bark
C. Compilation error
D. Animal sound
Solution
Step 1: Understand method call without virtual keyword
The sound method is not virtual, so the pointer type Animal* calls Animal's method.
Step 2: Determine output
Since sound is not virtual, Animal sound is printed.
Final Answer:
Animal sound -> Option D
Quick Check:
Non-virtual method calls base class method [OK]
Hint: Without virtual, base class method runs [OK]
Common Mistakes:
Assuming polymorphism without virtual
Expecting derived class method call
Ignoring pointer type effect
4. Identify the error in the following C++ code snippet:
class Vehicle {
private:
int speed;
public:
void setSpeed(int s) { speed = s; }
};
int main() {
Vehicle v;
v.speed = 100;
return 0;
}
medium
A. setSpeed method is not defined
B. Missing semicolon after class definition
C. Cannot access private member 'speed' directly
D. Vehicle object not created properly
Solution
Step 1: Check access to private member
The member speed is private and cannot be accessed directly outside the class.
Step 2: Identify the error in main()
Trying to assign v.speed = 100; causes an access violation error.
Final Answer:
Cannot access private member 'speed' directly -> Option C
Quick Check:
Private members need public methods for access [OK]
Hint: Private members can't be accessed outside class [OK]
Common Mistakes:
Trying to access private variables directly
Ignoring access specifiers
Assuming public by default
5. You want to design a C++ class hierarchy where a base class Shape defines a method area() but each derived class calculates area differently. Which OOP principle does this best demonstrate?
hard
A. Polymorphism
B. Inheritance
C. Encapsulation
D. Abstraction
Solution
Step 1: Understand the scenario of different area calculations
Each derived class implements area() differently, but shares the same interface.
Step 2: Identify the OOP principle
This is polymorphism: same method name, different behaviors in subclasses.
Final Answer:
Polymorphism -> Option A
Quick Check:
Same method, different behaviors = Polymorphism [OK]
Hint: Different behaviors, same method name = polymorphism [OK]
Common Mistakes:
Confusing with inheritance or abstraction
Thinking encapsulation means method overriding
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.