Font size
WorksheetsITP221-Midterms
Total questions: 42
Worksheet time: 38mins
What is object-oriented programming (OOP)?
A way of organizing code for maximum reusability.
A method for writing procedural code.
A technique for managing databases.
A programming language.
What is a class in OOP?
A user-defined data type.
A built-in data type.
A function that creates objects.
A method for data manipulation.
What is an object in OOP?
An instance of a class.
A blueprint for a class.
A type of function.
A method for data encapsulation.
What does encapsulation refer to in Python?
Bundling of data and methods together.
Hiding the internal state of an object.
Creating multiple classes.
Using inheritance.
What is inheritance in OOP?
Acquiring properties and methods from another class.
Creating new classes without any base class.
A method for data encapsulation.
A way to define functions.
What are the types of inheritance?
Single, Multiple, Multilevel, Hierarchical, Hybrid.
Public, Protected, Private.
Encapsulation, Abstraction, Inheritance.
Classes, Objects, Methods.
What is the purpose of the self parameter in Python?
To refer to the current instance of the class.
To create a new instance of a class.
To define a class method.
To access class attributes.
What are public members in Python?
Attributes and methods accessible from anywhere.
Attributes and methods intended for internal use.
Attributes and methods that cannot be accessed directly.
Attributes and methods that are private.
What are protected members in Python?
Attributes and methods intended for internal use.
Attributes and methods accessible from anywhere.
Attributes and methods that cannot be accessed directly.
Attributes and methods that are public.
What are private members in Python?
Attributes and methods that cannot be accessed directly.
Attributes and methods accessible from anywhere.
Attributes and methods intended for internal use.
Attributes and methods that are public.
What is the main benefit of using encapsulation in OOP?
It allows for data hiding and protects object integrity.
It simplifies the code structure.
It enables multiple inheritance.
It improves performance of the program.
What is the difference between a class and an object in OOP?
An object can exist without a class.
A class is a blueprint, while an object is an instance of that blueprint.
A class is a type of object.
There is no difference; they are the same.
What does the term 'method overriding' mean in OOP?
Calling a method from a parent class.
Creating a method with the same name in multiple classes.
Providing a new implementation for a method in a derived class.
Defining a method that cannot be changed.
What is the purpose of constructors in OOP?
To create a new class from an existing class.
To define methods for a class.
To initialize object attributes when an object is created.
To destroy an object when it is no longer needed.
Which of the following serves as a blueprint from which individual projects are created?
Object
Class
Method
Attribute
What type of attribute is specific to an object?
Dynamic Attribute
Static Attribute
Class Attribute
Instance Attribute
These are created from the Class design for each actual thing.
Abstraction
Encapsulation
Generalisation
Polymorphism
Object
The name of the default access specifier for the member functions or data members in the Python programming language is (a) .
Used in objects to hold data. They are similar, but different, from a variable.
Class Variables
Objects
Attributes
Constructors
A special method that Python uses to instantiate an instance or object. They assign values to instance variable, and are always named "__init__()"
Instances
Attributes
Constructors
Methods
What will be the output?
Parent class
Child class
Error
None
What will be the output?
Starting vehicle
Starting car
Error
None
What will be the output
Hello from Grandparent
Hello from Parent
Error
None
Why should private members not be accessed directly from outside the class?
Why is encapsulation important for modular programming?
What is the output of the given code?
Employee: Alice, Salary: 75000
Employee: Bob, Salary: 90000
Manager: Alice, Salary: 75000, Department: HR
Developer: Bob, Salary: 90000, Language: Python
Manager: Alice, Salary: 75000
Developer: Bob, Salary: 90000
Employee: Alice, Salary: 75000, Department: HR
Employee: Bob, Salary: 90000, Language: Python
What is the output of the given code?
Deposited 1500. New Balance: 6500
Withdrawn 2000. New Balance: 4500
Balance for John Doe: 4500
Deposited 1500. New Balance: 6500
Withdrawn 2000. New Balance: 5000
Balance for John Doe: 5000
Deposited 1500. New Balance: 6500
Withdrawn 2000. New Balance: 6500
Balance for John Doe: 6500
Deposited 1500. New Balance: 5000
Withdrawn 2000. New Balance: 3000
Balance for John Doe: 3000
What error will occur when running this code?
The program runs fine and prints the correct output.
The Student class does not call the Person constructor, so name and age may not be initialized correctly.
grade cannot be accessed in get_info().
get_info() should be defined inside Person only.
What error will occur when running this code?
The program runs fine and prints the correct output.
The Car class does not call the Vehicle constructor, so brand and model may not be initialized correctly.
year cannot be accessed in get_info().
get_info() should be defined inside Vehicle only.
Alex is a software developer working on a Python project that involves inheritance. He creates a base class called Device, which stores a device's brand and model. Then, he creates a subclass Smartphone that adds extra functionality. However, Alex forgets to properly initialize the parent class. What issue might Alex face when using this code?
The program will run correctly without any issues.
The Smartphone class does not call the Device constructor, which might lead to unexpected behavior if Device.__init__() contains additional logic.
The os attribute cannot be accessed because it is private.
The get_info() method should only be defined in Device.
Carlos is developing a banking system in Python. He creates a base class Account that stores a user's balance. Then, he creates a subclass SavingsAccount that adds an interest rate feature. However, when testing the program, he notices an issue. What issue might Carlos face when running this code?
The program runs correctly without any issues.
The SavingsAccount class does not call the Account constructor, which might lead to unexpected behavior if Account.__init__() has additional logic.
The interest_rate attribute cannot be accessed because it is private.
The get_balance() method should only be defined in Account.
What do you call the mechanism in Python that allows a child class to acquire the attributes and methods of a parent class?
What is the process of defining a method in a subclass with the same name as a method in the parent class but providing a different implementation?
What type of inheritance allows a class to inherit from multiple parent classes?
What do you call the special method in Python classes that is used to initialize an object’s attributes when an instance is created?
In Python, private attributes (with __double_underscore) can be accessed directly from a child class.
A subclass in Python can inherit from multiple parent classes.
Method overriding allows a subclass to provide a different implementation for a method already defined in the parent class.
True
False
What is your Instructor's Full Name.
