Java Reference
In-Depth Information
Class Definition
The following shows the form of a class definition that is most commonly used; however, it
is legal to intermix the method definitions and the instance variable declarations.
SYNTAX
public class Class_Name
{
Instance_Variable_Declaration_1
Instance_Variable_Declaration_2
. . .
Instance_Variable_Declaration_Last
Method_Definition_1
Method_Definition_2
. . .
Method_Definition_Last
}
EXAMPLES
See Displays 4.1 and 4.2.
is equivalent to
System.out.println(date1.month + " " + date1.day
+ ", " + date1.year);
Similarly,
date2.writeOutput();
is equivalent to
System.out.println(date2.month + " " + date2.day
+ ", " + date2.year);
File Names and Locations
Remember that a file must be named the same as the class it contains with an added
.java at the end. For example, a class named MyClass must be in a file named
MyClass.java .
We will eventually see other ways to arrange files, but at this point, your program and all the
classes it uses should be in the same directory (same folder).
Search WWH ::




Custom Search