Class 1, Part 2 | Intro to Java 30-IT-396 |
More About Constructors
public class Car {
private String make;
private String model;
private Color color;
private int year;
public Car() {
make = "Chevrolet";
model = "Cavalier";
Color = new Color(Color.black);
year = 2000;
}
public Car(String make, String model, Color color,
int year){
this.make = make;
this.model = model;
this.color = color;
this.year = year;
}
}
Where this refers to the current object, and the name alone
refers to the incoming parameter.
Created by: Brandan
Jones January 4, 2002