Classes And Objects In Python — Part 1 MCQs with Explanations
Practice high-yield Programming & Software Development MCQs on Classes And Objects In Python — Part 1 with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.
Questions
40
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
48 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
40
Verified Practice Questions
Interactive test mode with detailed academic worked solutions
Live Progress|0/40 answered
✓0 correct
✗0 wrong
0% score
🎉 Set complete! All 40 questions answered.
Question 1 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the following code: class Parent: def show(self): print('Parent method') class Child(Parent): pass obj = Child() obj.show()
Correct Answer: Option A — Parent method
Detailed Academic Explanation:
The correct answer is A: Parent method Here's why: We have a class called `Parent` that has a method named `show` . This method prints "Parent method". Then, we create another class called `Child` that inherits from the `Parent` class. This means the `Child` class automatically gets all the methods and attributes of the `Parent` class. Importantly, the `Child` class doesn't define its own `show` method. It inherits the `show` method directly from `Parent` . We create an object of the `Child` class called `obj` . When we call `obj.show()` , Python looks for a `show` method in the `Child` class. Since it doesn't find one there, it looks in the `Parent` class (because `Child` inherits from `Parent` ). It finds the `show` method in the `Parent` class and executes it. Therefore, it prints "Parent method".
💡Key Conceptual Anchor:Classes And Objects In Python
Question 2 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the following code: class MyClass: count = 0 def init(self): MyClass.count += 1 obj1 = MyClass() obj2 = MyClass() print(obj1.count)
Correct Answer: Option D — 0
Detailed Academic Explanation:
Let's break down this Python code step-by-step: First, we have a class called `MyClass`: This is like a blueprint for creating objects. Inside the class, we have `count = 0`: This is a class variable called `count`. It's shared by all instances (objects) of the `MyClass`. Initially, it's set to 0. Next, we have `def __init__(self):`: This is the constructor (initializer) of the class. It's automatically called when you create a new object of the class. Inside the constructor, we have `MyClass.count += 1`: This line increments the `count` class variable by 1 every time a new object is created. `MyClass.count` ensures we're updating the class variable, not an instance variable. Now, let's look at the object creation: `obj1 = MyClass()` This creates the first object of the class. The `__init__` method is called, and `MyClass.count` becomes 1. `obj2 = MyClass()` This creates the second object of the class. The `__init__` method is called again, and `MyClass.count` becomes 2. Finally, we have `print(obj1.count)`: This prints the value of the `count` variable. Since `count` is a class variable, `obj1.count` will access the class variable which is currently equal to 2. Therefore, the output is 2. So, the correct answer is Option A: 2
💡Key Conceptual Anchor:Classes And Objects In Python
Question 3 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is a class in Python?
Correct Answer: Option A — A blueprint for creating objects
Detailed Academic Explanation:
A blueprint for creating objects is the correct answer to “What is a class in Python”. This question is standard in competitive examination syllabi for Classes And Objects In Python.
💡Key Conceptual Anchor:Classes And Objects In Python
Question 4 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you define a class in Python?
Correct Answer: Option A — Using the class keyword
Detailed Academic Explanation:
Using the class keyword is the correct answer to “How do you define a class in Python”. This question is standard in competitive examination syllabi for Classes And Objects In Python.
💡Key Conceptual Anchor:Classes And Objects In Python
Question 5 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What are objects in Python?
Correct Answer: Option A — Instances of a class
Detailed Academic Explanation:
Instances of a class is the correct answer to “What are objects in Python”. This question is standard in competitive examination syllabi for Classes And Objects In Python.
💡Key Conceptual Anchor:Classes And Objects In Python
Question 6 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you create an object of a class in Python?
Correct Answer: Option A — Using the class name and parentheses
Detailed Academic Explanation:
Using the class name and parentheses is the correct answer to “How do you create an object of a class in Python”. This question is standard in competitive examination syllabi for Classes And Objects In Python.
💡Key Conceptual Anchor:Classes And Objects In Python
Question 7 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the self parameter in Python methods?
Correct Answer: Option A — It refers to the instance of the object
Detailed Academic Explanation:
It refers to the instance of the object is the correct answer to “What is the purpose of the self parameter in Python methods”. This question is standard in competitive examination syllabi for Classes And Objects In Python.
💡Key Conceptual Anchor:Classes And Objects In Python
Question 8 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How can you define a method in a Python class?
Correct Answer: Option A — By defining a function within the class
Detailed Academic Explanation:
By defining a function within the class is the correct answer to “How can you define a method in a Python class”. This question is standard in competitive examination syllabi for Classes And Objects In Python.
💡Key Conceptual Anchor:Classes And Objects In Python
Question 9 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How can you delete an attribute of an object in Python?
Correct Answer: Option A — By using the del keyword
Detailed Academic Explanation:
By using the del keyword is the correct answer to “How can you delete an attribute of an object in Python”. This question is standard in competitive examination syllabi for Classes And Objects In Python.
💡Key Conceptual Anchor:Classes And Objects In Python
Question 10 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is encapsulation in Python classes?
Correct Answer: Option A — The concept of bundling data and methods that operate on the data into a single unit
Detailed Academic Explanation:
The concept of bundling data and methods that operate on the data into a single unit is the correct answer to “What is encapsulation in Python classes”. This question is standard in competitive examination syllabi for Classes And Objects In Python.
💡Key Conceptual Anchor:Classes And Objects In Python
Question 11 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the @staticmethod decorator in Python classes?
Correct Answer: Option A — It defines a method that belongs to the class rather than an instance
Detailed Academic Explanation:
It defines a method that belongs to the class rather than an instance is the correct answer to “What is the purpose of the @staticmethod decorator in Python classes”. This question is standard in competitive examination syllabi for Classes And Objects In Python.
💡Key Conceptual Anchor:Classes And Objects In Python
Question 12 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the __init__ method used for in Python classes?
Correct Answer: Option A — It initializes the attributes of an object
Detailed Academic Explanation:
It initializes the attributes of an object is the correct answer to “What is the __init__ method used for in Python classes”. This question is standard in competitive examination syllabi for Classes And Objects In Python.
💡Key Conceptual Anchor:Classes And Objects In Python
Question 13 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How can you access the attributes of an object in Python?
Correct Answer: Option A — Using dot notation
Detailed Academic Explanation:
Using dot notation is the correct answer to “How can you access the attributes of an object in Python”. This question is standard in competitive examination syllabi for Classes And Objects In Python.
💡Key Conceptual Anchor:Classes And Objects In Python
Question 14 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How can you inherit a class in Python?
Correct Answer: Option A — By creating a new class that is based on an existing class
Detailed Academic Explanation:
By creating a new class that is based on an existing class is the correct answer to “How can you inherit a class in Python”. This question is standard in competitive examination syllabi for Classes And Objects In Python.
💡Key Conceptual Anchor:Classes And Objects In Python
Question 15 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is method overriding in Python classes?
Correct Answer: Option A — It allows a subclass to provide a specific implementation of a method that is already defined in its superclass
Detailed Academic Explanation:
It allows a subclass to provide a specific implementation of a method that is already defined in its superclass is the correct answer to “What is method overriding in Python classes”. This question is standard in competitive examination syllabi for Classes And Objects In Python.
💡Key Conceptual Anchor:Classes And Objects In Python
Question 16 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the __str__ method in Python classes?
Correct Answer: Option A — It returns a string representation of an object
Detailed Academic Explanation:
It returns a string representation of an object is the correct answer to “What is the purpose of the __str__ method in Python classes”. This question is standard in competitive examination syllabi for Classes And Objects In Python.
💡Key Conceptual Anchor:Classes And Objects In Python
Question 17 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the __del__ method in Python classes?
Correct Answer: Option A — It is called when an object is about to be destroyed
Detailed Academic Explanation:
It is called when an object is about to be destroyed is the correct answer to “What is the purpose of the __del__ method in Python classes”. This question is standard in competitive examination syllabi for Classes And Objects In Python.
💡Key Conceptual Anchor:Classes And Objects In Python
Question 18 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which function is called when the following Python code is executed? f = foo() format(f)
Correct Answer: Option D — __str__()
Detailed Academic Explanation:
__str__() is the correct answer to “Which function is called when the following Python code is executed? f = foo() format(f)”. This question is standard in competitive examination syllabi for Classes And Objects In Python.
💡Key Conceptual Anchor:Classes And Objects In Python
Question 19 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which operator is overloaded by __invert__()?
Correct Answer: Option B — ~
Detailed Academic Explanation:
~ is the correct answer to “Which operator is overloaded by __invert__()”. This question is standard in competitive examination syllabi for Classes And Objects In Python.
💡Key Conceptual Anchor:Classes And Objects In Python
Question 20 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which operator is overloaded by __lg__()?
Correct Answer: Option D — none of the mentioned
Detailed Academic Explanation:
none of the mentioned is the correct answer to “Which operator is overloaded by __lg__()”. This question is standard in competitive examination syllabi for Classes And Objects In Python.
💡Key Conceptual Anchor:Classes And Objects In Python
Question 21 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which operator is overloaded by the __or__() function?
Correct Answer: Option B — |
Detailed Academic Explanation:
| is the correct answer to “Which operator is overloaded by the __or__() function”. This question is standard in competitive examination syllabi for Classes And Objects In Python.
💡Key Conceptual Anchor:Classes And Objects In Python
Question 22 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is Instantiation in terms of OOP terminology?
Correct Answer: Option D — Creating an instance of class
Detailed Academic Explanation:
Creating an instance of class is the correct answer to “What is Instantiation in terms of OOP terminology”. This question is standard in competitive examination syllabi for Classes And Objects In Python.
💡Key Conceptual Anchor:Classes And Objects In Python
Question 23 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The assignment of more than one function to a particular operator is . . . . . . . .
Correct Answer: Option C — Operator overloading
Detailed Academic Explanation:
Operator overloading is the correct answer to “The assignment of more than one function to a particular operator is . . . . . . . .”. This question is standard in competitive examination syllabi for Classes And Objects In Python.
💡Key Conceptual Anchor:Classes And Objects In Python
Question 24 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the difference between a class variable and an instance variable in Python?
Correct Answer: Option A — A class variable is shared among all instances of a class, while an instance variable is unique to each instance
Detailed Academic Explanation:
A class variable is shared among all instances of a class, while an instance variable is unique to each instance is the correct answer to “What is the difference between a class variable and an instance variable in Python”. This question is standard in competitive examination syllabi for Classes And Objects In Python.
💡Key Conceptual Anchor:Classes And Objects In Python
Question 25 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How can you access a class variable in Python?
Correct Answer: Option A — Using the class name and dot notation
Detailed Academic Explanation:
Using the class name and dot notation is the correct answer to “How can you access a class variable in Python”. This question is standard in competitive examination syllabi for Classes And Objects In Python.
💡Key Conceptual Anchor:Classes And Objects In Python
Question 26 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
. . . . . . . . represents an entity in the real world with its identity and behaviour.
Correct Answer: Option B — An object
Detailed Academic Explanation:
An object is the correct answer to “. . . . . . . . represents an entity in the real world with its identity and behaviour.”. This question is standard in competitive examination syllabi for Classes And Objects In Python.
💡Key Conceptual Anchor:Classes And Objects In Python
Question 27 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
. . . . . . . . is used to create an object.
Correct Answer: Option B — constructor
Detailed Academic Explanation:
constructor is the correct answer to “. . . . . . . . is used to create an object.”. This question is standard in competitive examination syllabi for Classes And Objects In Python.
💡Key Conceptual Anchor:Classes And Objects In Python
Question 28 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What are the methods which begin and end with two underscore characters called?
Correct Answer: Option A — Special methods
Detailed Academic Explanation:
Special methods is the correct answer to “What are the methods which begin and end with two underscore characters called”. This question is standard in competitive examination syllabi for Classes And Objects In Python.
💡Key Conceptual Anchor:Classes And Objects In Python
Question 29 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is setattr() used for?
Correct Answer: Option B — To set an attribute
Detailed Academic Explanation:
To set an attribute is the correct answer to “What is setattr() used for”. This question is standard in competitive examination syllabi for Classes And Objects In Python.
💡Key Conceptual Anchor:Classes And Objects In Python
Question 30 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is getattr() used for?
Correct Answer: Option A — To access the attribute of the object
Detailed Academic Explanation:
To access the attribute of the object is the correct answer to “What is getattr() used for”. This question is standard in competitive examination syllabi for Classes And Objects In Python.
💡Key Conceptual Anchor:Classes And Objects In Python
Question 31 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the following code: class MyClass: x = 5 obj = MyClass() print(obj.x)
Correct Answer: Option C — obj
Detailed Academic Explanation:
obj is the correct answer to “What is the output of the following code: class MyClass: x = 5 obj = MyClass() print(obj.x)”. This question is standard in competitive examination syllabi for Classes And Objects In Python.
💡Key Conceptual Anchor:Classes And Objects In Python
Question 32 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Is the following Python code valid? class B(object): def first(self): print("First method called") def second(): print("Second method called") ob = B() B.first(ob)
Correct Answer: Option C — Yes, this method of calling is called unbounded method call
Detailed Academic Explanation:
Yes, this method of calling is called unbounded method call is the correct answer to “Is the following Python code valid? class B(object): def first(self): print("First method called") def second(): print("Second method called") ob = B() B.first(ob)”. This question is standard in competitive examination syllabi for Classes And Objects In Python.
💡Key Conceptual Anchor:Classes And Objects In Python
Question 33 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which function overloads the == operator?
Correct Answer: Option A — __eq__()
Detailed Academic Explanation:
__eq__() is the correct answer to “Which function overloads the == operator”. This question is standard in competitive examination syllabi for Classes And Objects In Python.
💡Key Conceptual Anchor:Classes And Objects In Python
Question 34 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? class stud: def __init__(self, roll_no, grade): self.roll_no = roll_no self.grade = grade def display (self): print("Roll no : ", self.roll_no, ", Grade: ", self.grade) stud1 = stud(34, 'S') stud1.age=7 print(hasattr(stud1, 'age'))
Correct Answer: Option B — True
Detailed Academic Explanation:
True is the correct answer to “What will be the output of the following Python code? class stud: def __init__(self, roll_no, grade): self.roll_no = roll_no self.grade = grade def display (self): print("Roll no : ", self.roll_no, ", Grade: ", self.grade) stud1 = stud(34, 'S') stud1.age=7 print(hasattr(stud1, 'age'))”. This question is standard in competitive examination syllabi for Classes And Objects In Python.
💡Key Conceptual Anchor:Classes And Objects In Python
Question 35 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does print(Test.__name__) display (assuming Test is the name of the class)?
Correct Answer: Option C — Test
Detailed Academic Explanation:
Test is the correct answer to “What does print(Test.__name__) display (assuming Test is the name of the class)”. This question is standard in competitive examination syllabi for Classes And Objects In Python.
💡Key Conceptual Anchor:Classes And Objects In Python
Question 36 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is a constructor in Python classes?
Correct Answer: Option A — A special method that is automatically called when an object is created
Detailed Academic Explanation:
A special method that is automatically called when an object is created is the correct answer to “What is a constructor in Python classes”. This question is standard in competitive examination syllabi for Classes And Objects In Python.
💡Key Conceptual Anchor:Classes And Objects In Python
Question 37 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following Python code will print True? a = foo(2) b = foo(3) print(a < b)
Correct Answer: Option C — class foo: def __init__(self, x): self.x = x def __lt__(self, other): if self.x < other.x: return True else: return False
Detailed Academic Explanation:
class foo: def __init__(self, x): self.x = x def __lt__(self, other): if self.x < other.x: return True else: return False is the correct answer to “Which of the following Python code will print True? a = foo(2) b = foo(3) print(a < b)”. This question is standard in competitive examination syllabi for Classes And Objects In Python.
💡Key Conceptual Anchor:Classes And Objects In Python
Question 38 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the @classmethod decorator in Python classes?
Correct Answer: Option A — It defines a method that belongs to the class and not the instance
Detailed Academic Explanation:
It defines a method that belongs to the class and not the instance is the correct answer to “What is the purpose of the @classmethod decorator in Python classes”. This question is standard in competitive examination syllabi for Classes And Objects In Python.
💡Key Conceptual Anchor:Classes And Objects In Python
Question 39 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the following code: class Parent: def init(self): print('Parent constructor') class Child(Parent): def init(self): print('Child constructor') obj = Child()
Correct Answer: Option A — Child constructor
Detailed Academic Explanation:
Child constructor is the correct answer to “What is the output of the following code: class Parent: def init(self): print('Parent constructor') class Child(Parent): def init(self): print('Child constructor') obj = Child()”. This question is standard in competitive examination syllabi for Classes And Objects In Python.
💡Key Conceptual Anchor:Classes And Objects In Python
Question 40 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How can you create a private attribute in a Python class?
Correct Answer: Option A — By prefixing the attribute name with an underscore (_)
Detailed Academic Explanation:
By prefixing the attribute name with an underscore (_) is the correct answer to “How can you create a private attribute in a Python class”. This question is standard in competitive examination syllabi for Classes And Objects In Python.
💡Key Conceptual Anchor:Classes And Objects In Python
✓Link copied to clipboard
Continue Your Practice
Advance Html — Part 1
Master the next curriculum module with 40 exam-standard MCQs.
💡Examiner's Advisory for Programming & Software Development
In competitive commission exams (FPSC, PPSC, KPPSC, SPSC, CSS, PMS), questions are frequently phrased with distractor options designed to catch rote learners. Whenever you answer an MCQ, read the Detailed Academic Explanation and Conceptual Anchor to understand why the remaining options are incorrect.