CodeStudy.net
Toggle Menu
Home
Online Java Compiler
Tutorials
Java Tutorial
Python Tutorial
SQL Database Design
Blog
All Posts
Object-Oriented Programming in Python
Review your understanding of classes,inheritance,and magic methods.
1. What keyword is used to define a class in Python?
def
class
object
new
2. Which of the following are types of methods in a Python class? (Select all that apply)
Instance method
Class method
Static method
Global method
3. Python supports multiple inheritance.
True
False
4. What is the term for the process of hiding the internal details of a class and exposing only necessary information? (one word)
5. Which method is automatically called when an object is created to initialize its attributes?
__create__
__init__
__new__
__make__
6. What type of inheritance occurs when a class inherits from more than one parent class?
Single
Multilevel
Multiple
Hierarchical
7. Which of the following statements about Python classes are true? (Select all that apply)
A class can inherit from another class
Python classes support method overloading by default
All attributes in a Python class are public by default
A class cannot have both instance and class attributes
8. What is the name for a function defined inside a class?
Variable
Method
Procedure
Function
9. The __new__ method is responsible for creating a new instance of a class.
True
False
10. Which of the following is an example of a class attribute?
An attribute defined inside __init__
An attribute defined outside any method in the class
An attribute passed to a method
A local variable in a method
11. Which of the following are considered pillars of Object-Oriented Programming? (Select all that apply)
Encapsulation
Inheritance
Polymorphism
Iteration
12. In a Python class, what is the conventional name for the first parameter of an instance method?
this
self
instance
obj
13. In Python, a child class can override a method from its parent class.
True
False
14. What are the characteristics of instance attributes? (Select all that apply)
Defined inside __init__
Shared by all instances of a class
Unique to each instance
Accessed using the class name
15. Which built-in function is used to check if an object is an instance of a specific class?
type()
isinstance()
isinstanceof()
check_type()
16. What keyword is used to call a method from the parent class within a child class? (one word)
17. Static methods in Python can access and modify class attributes directly without an instance.
True
False
18. What is the output of the following code? class MyClass: x = 5 obj = MyClass() print(obj.x)
5
Error
None
0
19. Which of the following are valid ways to define a class method in Python? (Select all that apply)
Using @classmethod decorator
Defining a method with 'cls' as the first parameter
Using @staticmethod decorator
Defining a method without any parameters
20. What is the special method used to delete an object in Python? (enclose in double underscores)
Reset
Answered 0 of 0 — 0 correct