Friday, March 09, 2007

The Keyword 'class'

A Java program consists of one or more classes. You may think of a class as a small, independent program, a container holding your code. A normal class declaration is defined in the grammar as:

NormalClassDeclaration =
[ClassModifiers], 'class', Identifier, [TypeParameters], [Super], [Interfaces], ClassBody ;

ClassModifiers, TypeParameters, Super and Interfaces are optional, so we skip them for now. So, let's take a look at a simple class:

class TinyClass {   
}

You start writing a class using the keyword class.

then you write an identifier that is the name of the class, TinyClass:

Identifier =
IdentifierChars - (Keyword | BooleanLiteral | NullLiteral) ;

and finally you write the class body { }:

ClassBody =
'{', [ClassBodyDeclarations], '}' ;

All Java code must be written inside the class body.

No comments: