Page 415 - Computer_Science_F5
P. 415
Computer Science def make_sound(self):
print(“Woof!”)
class Cat(Animal):
def make_sound(self):
FOR ONLINE READING ONLY
print(“Meow!”)
# Create instances of concrete classes
dog = Dog()
cat = Cat()
# Call the abstract method
dog.make_sound() # Output: Woof!
cat.make_sound() # Output: Meow!
Output:
Figure 6.10: Output of abstraction program code
Exercise 6.2 5. What is abstraction in Python
and how does it differ from
1. Explain the concept of encapsulation encapsulation?
in Python and why it is important 6. Explain the concept of abstract
in Object-Oriented Programming. classes and methods in Python.
2. How does encapsulation help Provide an example to illustrate
in achieving data hiding and their usage.
preventing direct access to class 7. How does abstraction help in
attributes in Python? simplifying complex systems and
3. Discuss the role of access promoting code reusability in
modifiers such as public, private, Python?
and protected in implementing 8. Discuss the benefits of using
encapsulation in Python. abstract classes and methods in
4. Provide an example of a Python Python programming, especially
class with private attributes and in large-scale projects.
demonstrate how encapsulation is 9. Define inheritance in Python and
used to access and modify these describe its role in Object-Oriented
attributes. Programming.
406
for Advanced Secondary Schools
Computer Science Form 5.indd 406 23/07/2024 12:34

