Script Valley
Python: Complete Language Course
Object-Oriented Programming/Assessment

Practice & Assessment

Test your understanding of Object-Oriented Programming

Multiple Choice Questions

5
1

What is the difference between a class attribute and an instance attribute?

2

What does `super().__init__(name)` accomplish in a child class?

3

Which method is called when you do `str(obj)` or `print(obj)`?

4

What happens if you try to instantiate a class that has an unimplemented `@abstractmethod`?

5

What does `@classmethod` provide that `@staticmethod` does not?

Coding Challenges

1
1

Bank Account class

Implement a `BankAccount` class with `owner` (str) and `balance` (float, default 0) attributes. Add `deposit(amount)` and `withdraw(amount)` methods that raise `ValueError` for negative or overdraft amounts. Add a `@property` for balance with a setter that prevents negative values. Implement `__repr__` and `__str__`. Test with deposits, withdrawals, and an attempt to overdraft. Input: method calls. Output: printed state and raised exceptions. Estimated time: 20-25 minutes.

Medium

Mini Project

1

Animal Shelter Management System

Design a small OOP system for an animal shelter. Create an abstract base class `Animal` with abstract methods `speak()` and `info()` and concrete method `describe()`. Implement concrete classes `Dog`, `Cat`, and `Bird` with appropriate attributes (name, age, breed). Create a `Shelter` class with a list of animals. Add methods to add/remove animals, find by name, and generate a summary report using `__str__`. Implement `__len__` on `Shelter` to return animal count. Use `@classmethod` to create animals from a dictionary. Demonstrate polymorphism by calling `speak()` on all animals in a loop.

Medium