Skip to content

Instantly share code, notes, and snippets.

@ryanorsinger
Created September 2, 2019 01:29
Show Gist options
  • Save ryanorsinger/d1049ac3048763ade386a685a7f0eee2 to your computer and use it in GitHub Desktop.
Save ryanorsinger/d1049ac3048763ade386a685a7f0eee2 to your computer and use it in GitHub Desktop.
Object Examples
public class Car {
// properties that belong to each object
String make;
String model;
// This runs every time we create the car object. This is the constructor.
public Car(String make, String model) {
this.make = make;
this.model = model;
}
public String getMake() {
return make;
}
public String getModel() {
return model;
}
public void printCarInfo() {
System.out.println("This vehicle is a " + make + ", " + model + ".");
}
public static void main(String[] args) {
Car yourCar = new Car("Toyota", "Prius");
yourCar.printCarInfo();
System.out.println(yourCar);
Car myCar = new Car("Subaru", "Outback");
myCar.printCarInfo();
System.out.println(myCar);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment