![]() |
![]() |
![]() |
![]() |
![]() |
|
You can combine several class-variable
declarations, as is done in the following example. There, several class
variables are declared and initialized for use instead of literal numbers
in the movieRating method:
public class Movie {
// Define class variables:
public static int wScript = 6, wActing = 13, wDirection = 11;
// Define movieRating:
public static int movieRating (int s, int a, int d) {
return wScript * s + wActing * a + wDirection * d;
}
}
In the example, variable names provide access to the class-variable values, because the variables and the method in which they appear are defined in the same class.