TK Study

Multiple choice › OOP

OOP

1. OOP

Which OOP concept is shown when a class keeps its data private and exposes it only through methods?

  1. Polymorphism
  2. Inheritance
  3. Abstraction
  4. 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:

  1. Encapsulation
  2. Iteration
  3. Sequencing
  4. 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:

  1. Inheritance
  2. Encapsulation
  3. Abstraction of a loop
  4. Recursion
Answer

A

Subclasses inherit attributes and methods from the superclass, reducing duplicated code.