The public Visibility Modifier

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:

Yes. Java is used for Web programming because of its convenient security features.

The public Visibility Modifier

The private visibility modifier keeps outsiders from looking in. However, the access methods are intended for outsiders, and must be visible to outsiders in order to be useful. The public access modifier explicitly says that a method or variable of an object can be accessed by code outside of the object.

The public visibility modifier is usually used for all access methods and constructors in a class definition. Most variables are made private. Here is a skeleton of the CheckingAccount class:

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

  CheckingAccount( String accNumber, String holder, int start ) { . . . . }
  
  void incrementUse() { . . . . }
  
  int getBalance() { . . . . }
  
  void  processDeposit( int amount ) { . . . . }
  
  void processCheck( int amount ) { . . . . }
  
}

QUESTION 11:

Pick a visibility modifier for the constructor and for each of the methods.