Classes Questions and Answers
Practice ModeShowing 10 of 25 questions
Q1
What is the purpose of the __init__ method in a Python class?
Answer: Option B
Explanation: The __init__ method is a constructor that initializes new objects when they are created.
Q2
Which keyword is used to create a class in Python?
Answer: Option A
Explanation: The "class" keyword is used to define a new class in Python.
Q3
What does "self" represent in a class method?
Answer: Option C
Explanation: The "self" parameter refers to the current instance of the class.
Q4
Which method is called when an object is created?
Answer: Option B
Explanation: The __init__ method is the constructor called when a new object is instantiated.
Q5
What is inheritance in Python classes?
Answer: Option C
Explanation: Inheritance allows a class to inherit attributes and methods from another class.
Q6
How do you call a parent class method from a child class?
Answer: Option B
Explanation: The super() function is used to call parent class methods.
Q7
What is method overriding in Python?
Answer: Option C
Explanation: Method overriding allows a child class to provide a specific implementation of a method already defined in its parent class.
Q8
What is encapsulation in OOP?
Answer: Option C
Explanation: Encapsulation is the bundling of data and methods that operate on that data within one unit (class).
Q9
How do you create a private variable in Python?
Answer: Option C
Explanation: Private variables in Python are created by prefixing the variable name with double underscores.
Q10
What is polymorphism in Python?
Answer: Option B
Explanation: Polymorphism allows methods to do different things based on the object that is acting upon them.