Python OOPs MCQ Questions and Answers
Q. What is the fundamental concept behind Object-Oriented Programming (OOP)?
A. EncapsulationB. Inheritance
C. Abstraction
D. Polymorphism
Q. What is a class in Python OOP?
A. A blueprint for creating objectsB. An instance of an object
C. A collection of functions
D. A data structure to store information
Q. How do you create an object from a class?
A. class_name(parameters)B. class_name = object
C. object(class_name)
D. object = class_name()
Q. What is a constructor in Python OOP?
A. A method used to initialize an objectB. A method used to destroy an object
C. A method used to copy an object
D. A method used to return a value
Q. What is the purpose of the "__init__" method in a class?
A. To initialize the attributes of an objectB. To return a value from an object
C. To destroy an object and release resources
D. To copy the values of one object to another
Q. What is encapsulation in Python OOP?
A. Wrapping data and methods into a single unitB. Hiding the internal details of an object
C. Defining the structure of a class
D. Creating a copy of an object
Q. How do you define a class attribute in Python?
A. Using the "self" keywordB. Using the "class" keyword
C. Using the "@classattribute" decorator
D. Using the "static" keyword
Q. How do you define an instance attribute in Python?
A. Using the "self" keywordB. Using the "instance" keyword
C. Using the "@instanceattribute" decorator
D. Using the "static" keyword
Q. What is inheritance in Python OOP?
A. The ability to create new classes based on existing classesB. The process of hiding internal details of a class
C. The concept of bundling data and methods into a single unit
D. The ability to copy the values of one object to another
Q. What is a parent class in inheritance?
A. The class that inherits from another classB. The class that is inherited by another class
C. The class that defines the common properties
D. The class that overrides the parent class methods
def calculate_average(numbers): total = sum(numbers) average = total / len(numbers) return average numbers = [1, 2, 3, 4, 5] avg = calculate_average(numbers) print(avg)
Q. What is a child class in inheritance?
A. The class that inherits from another classB. The class that is inherited by another class
C. The class that defines unique properties
D. The class that overrides parent class methods