Academic Java    Java Tutorial  >  Basics  >  a class

a class Example

Java a class EXAMPLE output The source code in the program below contains a class definition.

In Java a program (also called an application) contains one or more class definitions. The simple program below contains just one class definition.
1
2
3
4
5
6
7
8
9
10
11
class ClassExample {

   public static void main(String[] args) {

      ABox b = new ABox(java.awt.Color.red);

      b.draw();

   }

}

1-11 This is the class definition.
Notice the opening curly brace { at the end of the first line and the corresponding closing curly brace } on the last line.

3-9 Inside this class definition, the part between its curly braces, is a method definition.
A class definition can contain a variety of things, including any number of method definitions.