Back to Writing Classes

Lesson PreviewLesson 6 of 10 in this unit

5.6 Writing Methods

Part of Writing Classes in AP® Computer Science A. Read the opening section, then create a free account for the full interactive lesson, practice, and progress tracking.

As we have discussed in unit 2, there are different categories of methods, with each having its own use cases. In this lesson, we will learn to apply some of these principles discussed earlier to write methods effectively.

Encapsulation is a principle in object-oriented programming that restricts direct access to an object's internal state and encourages controlled interaction through getter and setter methods.

Parameters allow methods to accept inputs that customize their behavior. Below is a Book class that calculates the time required to read a book.

Continue the full lesson in Stellar

Create a free account to unlock the remaining sections, checkpoints, course practice, and progress tracking for AP® Computer Science A.