Classes and Objects Flashcards
The _______ keyword is used to define a class in Python.
class
An instance of a class is called an _________.
object
__________________ is the principle of restricting direct access to some attributes.
Encapsulation
The process where one class derives from another class is called _____________.
inheritance
The ability of a function to behave differently based on the object calling it is known as _________________.
polymorphism
A _______________ is a special method used for initializing objects in Python.
constructor
_______________ is the process of hiding implementation details and only showing the necessary functionality.
Abstraction
The method used to access private attributes in a class is called a __________.
getter
A ____________ is a class that inherits from another class.
subclass
Which of the following is NOT a pillar of OOP? a) Encapsulation
b) Compilation
c) Polymorphism
d) Inheritance
b) Compilation
What does the super() function do?
a) Creates an object
b) Calls the parent class constructor
c) Deletes an object
d) Defines an abstract method
b) Calls the parent class constructor
What is the purpose of the self keyword in Python classes?
a) Refers to the instance of the class
b) Calls the parent class constructor
c) Defines a static method
d) Hides class attributes
a) Refers to the instance of the class
Which OOP concept allows multiple classes to have methods with the same name?
a) Encapsulation
b) Abstraction
c) Polymorphism
d) Inheritance
c) Polymorphism
What is the primary purpose of inheritance in OOP?
a) To increase code duplication
b) To allow reusability of code
c) To make variables private
d) To hide methods
b) To allow reusability of code
Which of the following best describes abstraction?
a) Hiding unnecessary details
b) Preventing access to variables
c) Overriding methods
d) Allowing multiple inheritances
a) Hiding unnecessary details
Which keyword is used to define a class in Python?
a) object
b) define
c) class
d) function
c) class
What is an instance method in Python?
a) A method that belongs to an instance of a class
b) A method that only belongs to a superclass
c) A method that can only be called once
d) A method that is declared as static
a) A method that belongs to an instance of a class
What is the term used for creating an object from a class?
a) Instantiation
b) Abstraction
c) Overriding
d) Declaration
a) Instantiation
What is the term for a class that cannot be instantiated and only serves as a base class?
Abstract class
What keyword is used to inherit from another class in Python?
super()
What is the process of restricting direct access to an object’s attributes?
Encapsulation
What is the method used to initialize an object’s attributes in Python classes?
init()
What is the term for an object’s ability to take many forms?
Polymorphism
What is the technique of reusing code by creating a new class from an existing class?
Inheritance
What is the act of creating an object from a class called?
Instantiation
What Python module is used for implementing abstract classes?
abc module