Created
September 2, 2019 01:29
-
-
Save ryanorsinger/d1049ac3048763ade386a685a7f0eee2 to your computer and use it in GitHub Desktop.
Object Examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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