Objects Questions and Answers

Practice Mode
Showing 10 of 25 questions
Q1
What is an object in Python?
  • A A blueprint for creating instances
  • B An instance of a class
  • C A built-in function in Python
  • D A module containing multiple functions
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?
  • A __init__
  • B __new__
  • C __create__
  • D __start__
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?
  • A It refers to the class itself
  • B It refers to the current object instance
  • C It is a reference to the parent class
  • D It indicates a static method
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?
  • A Using inheritance to create subclasses
  • B Using private variables with double underscores
  • C Overloading operators
  • D Using multiple inheritance
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?
  • A class MyClass:
  • B def MyClass():
  • C new class MyClass:
  • D create class MyClass:
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?
  • A Creating multiple instances of a class
  • B A class deriving properties from another class
  • C Hiding implementation details
  • D Converting one data type to another
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?
  • A __repr__
  • B __str__
  • C __string__
  • D __format__
Answer: Option B
Explanation: The __str__ method returns a human-readable string representation of the object.
Q8
What is polymorphism in Python?
  • A Creating multiple classes with same name
  • B Ability to take many forms
  • C Hiding complex implementation
  • D Converting objects to strings
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?
  • A new MyClass()
  • B MyClass.create()
  • C MyClass()
  • D create MyClass
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?
  • A Class variables are immutable, instance variables are mutable
  • B Class variables are shared, instance variables are per object
  • C Class variables can only be strings
  • D Instance variables are defined outside the class
Answer: Option B
Explanation: Class variables are shared among all instances, while instance variables are unique to each object.
Questions and Answers for Competitive Exams Various Entrance Test