... parentheses to specify an initial value for an Account object’s name instance variable—you’ll enhance class Account to enable this. For now, we simply leave the parentheses empty. Line 8 contains a class instance creation expression for a Scanner object—the expression initializes the Scanner with System.in, which tells the Scanner where to read the input from (i.e., the keyboard).

Calling Class Account’s getName Method

Line 14 displays the initial name, which is obtained by calling the object’s getName method. Just as we can use object System.out to call its methods print, printf and println, we can use object myAccount to call its methods getName and setName. Line 14 calls getName using the myAccount object created in line 11, followed by a dot separator ...

Get Java How to Program, Early Objects, 11th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.