instances

This commit is contained in:
2020-03-28 14:45:55 +01:00
commit cc9ef0fd57
16 changed files with 254 additions and 0 deletions

16
java/instances/Car.java Normal file
View File

@ -0,0 +1,16 @@
/*
Basic Car class
just here to make the demonstration in the main file possible
explanation of the code here will be given in later lessons
*/
public class Car {
public String model = "";
public String manufacturer = "";
public String get_info() {
return "Car Information:\n- manufacturer: " + this.manufacturer + "\n- model: " + this.model;
}
}

18
java/instances/main.java Normal file
View File

@ -0,0 +1,18 @@
public class main {
public static void main(String[] args) {
// create a new car and store it in the variable 'a'
Car a = new Car();
// set some data for that car
a.manufacturer = "Benz";
a.model = "Velo";
// Do the same for a second car
Car b = new Car();
b.manufacturer = "Ford";
b.model = "Model T";
// use a function of the car class to print out the information
System.out.println(a.get_info());
System.out.println(b.get_info());
}
}