nextRound
TechnologiesCoding ProblemsBookmarksLearning PathsLogin
nextRound
TechnologiesCoding ProblemsBookmarksLearning PathsLogin
nextRound

AI-powered interview preparation platform. Practice with curated questions, mock interviews, and personalized learning paths to crack your dream tech interview.

Quick Links

  • Technologies
  • Mock Interviews
  • Saved Questions
  • Pricing

Company

  • About Us
  • Contact Us

Legal

  • Privacy Policy
  • Terms of Use

© 2026 nextRound. All rights reserved.

Questions
12 of 19
1How would you make a custom class usable in a for loop?
2How do __enter__ and __exit__ work together to implement the context manager protocol?
3How does Python implement inheritance, and what is the Method Resolution Order (MRO)?
4What are dataclasses, and how do they reduce boilerplate compared to manually writing __init__, __eq__, and __repr__?
5What is the @property decorator, and what problem does it solve compared to plain getter/setter methods?
6What is the difference between method overriding and method overloading, and why doesn't Python natively support overloading?
7What problem does the diamond inheritance pattern cause, and how does Python's MRO resolve it?
8What is the difference between a class and an instance in Python?
9How does Python implement encapsulation given that it has no true 'private' access modifiers?
10What is the purpose of self in instance methods, and why must it be explicitly declared in Python?
11What is the difference between __str__ and __repr__, and what convention should __repr__ follow?
12What is a metaclass, and what is type's relationship to every class in Python?
13What is the purpose of __eq__ and __hash__, and why must they be implemented consistently?
14What is a descriptor, and how do @property and ORMs like Django's models rely on the descriptor protocol?
15What is the difference between an instance method, a class method, and a static method?
16What is composition, and why is 'favor composition over inheritance' often recommended?
17What are dunder (magic) methods, and how do they enable operator overloading?
18When would you use a metaclass instead of a class decorator or __init_subclass__?
19How do abstract base classes (abc.ABC) enforce interface contracts in Python?
PythonPython
Basics
Control Flow and Functions
Data Structures
Comprehensions & Functional Programming
Iterators, Generators & Decorators
Object-Oriented Programming
Exception Handling & Debugging
Concurrency & Parallelism
Performance & Optimization
Testing
Security
Modules, Packaging & Environment
Type Hinting & Modern Python
System Design & Architecture with Python
Best Practices & Design Patterns
Edge Cases & Tricky Interview Questions
12 / 19

What is a metaclass, and what is type's relationship to every class in Python?

Difficulty: 9/10
Metaclasses, Type, Class Creation

A metaclass is the class of a class; type is the default metaclass for every class

In Python, classes are objects. Their type is a metaclass, and by default that metaclass is type. When the interpreter executes a class statement, it collects the namespace and calls metaclass(name, bases, namespace), which returns the class object. So every class is an instance of its metaclass, and type is the root metaclass that builds classes. A custom metaclass subclasses type and overrides new or init to transform the class at creation time. The most common need is validation or registration of all subclasses, which can also be done with init_subclass or a class decorator.

  1. 1

    type(obj) returns the class of an instance; type(SomeClass) returns its metaclass, usually type.

  2. 2

    Class creation order: prepare produces the namespace dict, metaclass new builds the class, then init finalizes it.

  3. 3

    type(name, bases, dict) is the three-argument form that builds a class dynamically.

  4. 4

    ABCMeta is the canonical built-in metaclass; it powers abc.ABC and virtual subclass registration.

  5. 5

    Trade-off: metaclasses are powerful but affect every subclass, can conflict when multiple bases have different metaclasses, and complicate debugging.

  6. 6

    Common mistake: reaching for a metaclass when init_subclass or a class decorator would be simpler and safer.

  7. 7

    Version note: init_subclass and set_name were added in 3.6 specifically to reduce the need for custom metaclasses.

javascript

Scenario Questions

0-2 years experience

  1. 1What does type(SomeClass) return?
  2. 2How do you create a class without the class statement?

2-5 years experience

  1. 1You want every subclass to register itself automatically. Would you use a metaclass or __init_subclass__, and why?
  2. 2You define a metaclass and get a metaclass conflict when combining base classes. How do you resolve it?

5-8 years experience

  1. 1You need to enforce that every subclass defines a specific method. How do you implement that check at class creation time?
  2. 2You need to transform method signatures at class creation. Which hook do you use and what are the risks to introspection and typing?

8+ years experience

  1. 1Design a framework that lets plugins extend class behavior without requiring users to know about the metaclass.
  2. 2Compare metaclasses, __init_subclass__, and class decorators on composability, introspection, typing, and performance, and recommend a default for library authors.

Follow-up Questions

  • What happens if two bases declare different metaclasses?
  • How does ABCMeta differ from a plain metaclass?
Sharethis question

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.