1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to Object-Oriented Programming in Java

Connected

Exercise

Making methods private

Private methods can also be used to make code modular by encapsulating logic into smaller, reusable methods that can be used. You will add a method to deploy airbags in the Car class. You would not want this method to be one that can be accessed from the outside, for security reasons.

Instructions

100 XP
  • Create a private method called deployAirbags as a void method that takes no parameters.
  • Inside the deployAirbags method, print out the message "airbags deployed" .