Chapter 7Methods and Encapsulation


  • Creating and Using Methods
    • Create methods and constructors with arguments and return values
    • Create and invoke overloaded methods
    • Apply the static keyword to methods and fields
  • Applying Encapsulation
    • Apply access modifiers
    • Apply encapsulation principles to a class

In previous chapters, you learned how to use methods without examining them in detail. In this chapter, you’ll explore methods in depth, including overloading. This chapter discusses instance variables, access modifiers, and encapsulation.

Designing Methods

Every interesting Java program we’ve seen has had a main() method. You can write other methods, too. For example, you can write a basic method ...

Get OCP Oracle Certified Professional Java SE 11 Developer Complete Study Guide now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.