With the Java(TM) programming language, every computer program must define one or more user-defined data types via the class construct. For example, to create a program that behaves like a dog, we can define a class that (minimally) represents a dog:
class Dog {
void bark() {
System.out.println("Woof.");
}
}
This user-defined data type begins with the keyword class, followed by the name for the data type, in this case, Dog, followed by the specification of what it is to be a dog between opening and closing curly brackets. This simple example provides no data fields, only the single behavior of barking, as represented by the method bark().
copyright 1996-2000 Magelang Institute dba jGuru