Abstraction in Python MCQs Exercise I


Ques 1 Abstraction


What is abstraction in Python?
  a) Hiding implementation details
  b) Exposing implementation details
  c) Creating complex data structures
  d) Ignoring error handling


a is the correct option





Ques 2 Abstraction


What is the purpose of an abstract method in Python?
  a) It's used for private functionality.
  b) It's automatically inherited from the base class.
  c) It's optional to implement in the derived class.
  d) It must be implemented in the derived class.


d is the correct option





Ques 3 Abstraction


In Python, what is the purpose of providing default implementations in an abstract class?
  a) To prevent derived classes from overriding methods.
  b) To make the class non-abstract.
  c) To provide a starting point for derived classes.
  d) To increase the speed of method execution.


c is the correct option





Ques 4 Abstraction


What is the output of the following python Code?

from abc import ABC, abstractmethod
class Shape(ABC):
    @abstractmethod
    def area(self):
        pass
class Circle(Shape):
    def __init__(self, radius):
        self.radius = radius
    def area(self):
        return 3.14 * self.radius * self.radius
circle = Circle(5)
print(circle.area())

  a) 31.4
  b) 78.5
  c) 15.7
  d) Error: Cannot instantiate abstract class


b is the correct option