3.3 Declaring classes

Previous Index Next 


All code in Java must reside in a class. No procedures or functions exist in Java, only methods on classes exist. In general only one Java class is declared in a single Java source file and the source file has the same name as the class declared in it.

A Java class is declared as follows:
 

[ClassModifier] class ClassIdentifier [extends SuperClassIdentifier] [implements InterfaceIndentifiers]
 {
   ClassBody
 }
Where  For example the following code declares a public class called point that has attributes x and y.
public class Point
 {
  int x;
  int y;
 }