Home Segments Top Top Previous Next

212: Mainline

Now, suppose that you want to provide values for the script, acting, and direction instance variables when you create certain Movie instances. You should define a constructor with three parameters:

public class Movie {
 public int script, acting, direction;
 public Movie() {
  script = 5; acting = 5; direction = 5;
 }
 public Movie(int s, int a, int d) {            
  script = s; acting = a; direction = d;        
 }                                              
 public int rating () { 
  return script + acting + direction; 
 } 
} 

Note that the constructor for three parameters, like the one for zero parameters, is named for the class in which it appears.