24 lines
830 B
Java
24 lines
830 B
Java
public class Car {
|
|
|
|
// define the fields as private to prevent outside classes from accessing them
|
|
// access restriction will be a topic in the next lesson
|
|
private String model = "";
|
|
private String manufacturer = "";
|
|
|
|
// define the constructor
|
|
// in java a constructor is basically a function without return type named exactly like the class
|
|
public Car(String manufacturer, String model) {
|
|
// set manufacturer of the current object to the given manufacturer
|
|
this.manufacturer = manufacturer;
|
|
// set model of the current object to the given model
|
|
this.model = model;
|
|
}
|
|
|
|
// create the method print_info()
|
|
public void print_info() {
|
|
System.out.println("Car Information:");
|
|
System.out.println("- manufacturer: " + this.manufacturer);
|
|
System.out.println("- model: " + this.model);
|
|
}
|
|
}
|