Encapsulation

Hands-on practice for this lecture. Work through the exercises and quizzes to reinforce what you've learned.

1

Exercise 1 of 1

Protecting the TV: Access Modifiers

Practice the first pillar of OOP by deciding what parts of a system should be Public, Private, or Protected.

Public

The Remote Control: Anyone can access.

turnOn()
changeChannel()
volumeUp()

Private

Internal Wires: Only the TV can touch.

circuitBoard
powerSupply
displayDriver

Protected

Service Panel: Only family/children can access.

firmwareUpdate()
colorCalibration()
systemLogs

Assign Modifiers to the TV Components:

powerButton
messyInternalWires
volumeDown()
manufacturerDiagnostics()
electricityVoltage
screenBrightness

Make sure users don't touch the wires!

Hands-on Labs

Practical exercises to master the concepts.

Practical Lab
Encapsulation

Safe Bank Account

Create a BankAccount with a private balance. Add methods to deposit and withdraw. The withdraw method should prevent overdrawing.

Try implementing this on your own first!
Practice: Encapsulation — Interactive Exercises | Durgesh Rai