Multiple choice › OOP
OOP
1. OOP
Which OOP concept is shown when a class keeps its data private and exposes it only through methods?
- Polymorphism
- Inheritance
- Abstraction
- Encapsulation
Answer
D
Encapsulation bundles data with the methods that operate on it and restricts direct access.
2. OOP
A Dog class and a Cat class both have a speak() method that produces a different sound. This is:
- Encapsulation
- Iteration
- Sequencing
- Polymorphism
Answer
D
Polymorphism: the same method name behaves differently depending on the object's class.
3. OOP
A Car class and a Truck class both take attributes and methods from a Vehicle class. This is:
- Inheritance
- Encapsulation
- Abstraction of a loop
- Recursion
Answer
A
Subclasses inherit attributes and methods from the superclass, reducing duplicated code.