Objects Questions and Answers
Practice ModeShowing 10 of 25 questions
Q1
What is an object in Python?
Answer: Option B
Explanation: An object is an instance of a class that contains both data (attributes) and methods (functions) to manipulate that data.
Q2
Which method is called when an object is created in Python?
Answer: Option A
Explanation: The __init__ method is automatically called when a new instance of a class is created.
Q3
What is the purpose of the "self" parameter in Python class methods?
Answer: Option B
Explanation: The "self" parameter refers to the current instance of the class and is used to access variables and methods belonging to that object.
Q4
Which of the following is an example of encapsulation in Python objects?
Answer: Option B
Explanation: Encapsulation is achieved by using private variables and methods that can only be accessed within the class.
Q5
How do you create a class in Python?
Answer: Option A
Explanation: Classes are defined using the class keyword followed by the class name and a colon.
Q6
What is inheritance in Python?
Answer: Option B
Explanation: Inheritance allows a class to inherit attributes and methods from another class.
Q7
Which method is used to represent an object as a string?
Answer: Option B
Explanation: The __str__ method returns a human-readable string representation of the object.
Q8
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.
Q9
How do you create an instance of a class in Python?
Answer: Option C
Explanation: Objects are created by calling the class name followed by parentheses.
Q10
What is the difference between class variables and instance variables?
Answer: Option B
Explanation: Class variables are shared among all instances, while instance variables are unique to each object.