main() Can't use a Private Method

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

Answer:

  private void incrementUse()
  {
    useCount = useCount + 1; 
  }

main() Can't use a Private Method

Here is a main() that mistakenly tries to change useCount:

class CheckingAccount
{
  private String accountNumber;
  private String accountHolder;
  private int    balance;
  private int    useCount = 0;
  . . . .

  private void incrementUse()
  . . . .
}

class CheckingAccountTester
{
  public static void main( String[] args )
  {
    CheckingAccount bobsAccount = new CheckingAccount( "999", "Bob", 100 );

    bobsAccount.processCheck( 50 );
    bobsAccount.incrementUse();
    bobsAccount.useCount = 15;
  }
}

QUESTION 9:

Will this program compile and execute?