Syntax of a Class Definition

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. A big program might need thousands of objects as it runs, but might have only a few dozen class descriptions.

Syntax of a Class Definition

Class definitions look like this:

class ClassName
{

  Descriptions of the instance variables and methods each object
  will have and the constructors that initialize a new object.

}

Often programmers separate the definition into three sections:

class ClassName
{
  // Description of the variables.

  // Description of the constructors.

  // Description of the methods.
}

Separating the class into sections is done for clarity. It is not a rule of the language. A simple class might have just a few variables and be defined in just a few lines of code. A large, complicated class might take thousands of lines of code for its definition.

QUESTION 6:

Does each object require a main() method?