Define object-oriented programming.
A programming paradigm based on the concept of objects, which can contain data and code.
What is an object in OOP?
An instance of a class that contains attributes and methods.
True or false: Encapsulation hides the internal state of an object.
TRUE
Encapsulation restricts direct access to some of an object’s components.
Fill in the blank: Inheritance allows a class to _______ properties of another class.
inherit
What is a class in OOP?
A blueprint for creating objects, defining attributes and methods.
Define polymorphism.
The ability to present the same interface for different data types.
What does the self keyword represent in Python?
It refers to the instance of the class in method definitions.
True or false: A class can have multiple constructors in Python.
FALSE
Python does not support method overloading, including constructors.
What is the purpose of the __init__ method?
To initialize an object’s attributes when it is created.
Fill in the blank: A method is a function defined within a _______.
class
What is abstraction in OOP?
The concept of hiding complex implementation details and showing only essential features.
Define class variable.
A variable that is shared among all instances of a class.
What is a module in Python?
A file containing Python code that can define functions, classes, and variables.
True or false: Composition is a way to achieve code reuse by including objects in other objects.
TRUE
Composition allows building complex types by combining simpler ones.
What does super() do in Python?
It allows access to methods from a parent class.
Fill in the blank: A getter method retrieves the value of a _______.
property
What is the purpose of a setter method?
To set or update the value of a property in a class.
Define abstract class.
A class that cannot be instantiated and is meant to be subclassed.
What is method overriding?
When a subclass provides a specific implementation of a method already defined in its superclass.
True or false: An interface defines methods without implementing them.
TRUE
Interfaces are used to enforce certain functionalities in classes.
What is a constructor?
A special method that is called when an object is instantiated.
Fill in the blank: Duck typing in Python means that the type of an object is determined by its _______.
behavior
What is the significance of __str__ method?
It defines a string representation of an object for printing.
Define instance variable.
A variable that is unique to each instance of a class.