ProgrammingHardTCS NQT · Infosys pattern

What is printed?

What is printed?
from abc import ABC, abstractmethod
class Shape(ABC):
    @abstractmethod
    def area(self):
        pass
try:
    s = Shape()
except TypeError:
    print("TypeError")
  1. A. TypeError
  2. B. None
  3. C. Shape()
  4. D. NotImplementedError

Correct answer: A. TypeError

A class with an unimplemented @abstractmethod cannot be instantiated directly; Python raises TypeError ('Can't instantiate abstract class Shape with abstract method area') the moment Shape() is called.

More Python Programming questions

Exams that ask this topic