What Members of an Object can be Seen?

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page

What does the expression   account1.accountNumber   mean?

Answer:

The expression means to use the variable accountNumber that is part of the object referred to by account1.

What Members of an Object can be Seen?

The dot operator is how you access a member of an object:

referenceToAnObject . partOfTheObject

Of course, an object has to exist, and there has to be a reference to it. In the program, this happened when the object was constructed:

CheckingAccount account1 
        = new CheckingAccount( "123", "Bob", 100 );

When a method has a reference to an object, the method can:

  1. access the object's instance variables using dot notation, and
  2. call the object's methods using dot notation.

However, it is common for a class to have private variables and methods. Only methods of the class can access these. This will be discussed further in the next chapter.

QUESTION 9:

Can the main() method of TesterClass see the statements in the methods of SomeClass?