This commit is contained in:
2020-05-03 15:12:03 +02:00
parent 8143d66e49
commit f5c60a26f2
19 changed files with 340 additions and 9 deletions

18
java/classes/Car.java Normal file
View File

@ -0,0 +1,18 @@
/**
* this class is also declared with the public keyword to make it accessible
* outside of the current file
*/
public class Car {
public String model = "";
public String manufacturer = "";
public void print_info() {
System.out.println("Car Information:");
/**
* To access fields of the current object the this keyword is used. It is
* possible to omit that keyword, but it's recommended to be used anyways.
*/
System.out.println("- manufacturer: " + this.manufacturer);
System.out.println("- model: " + this.model);
}
}

5
java/classes/README.md Normal file
View File

@ -0,0 +1,5 @@
# Java Example
Relevant Files:
- [Car.java](./Car.java)

18
java/classes/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
a.print_info();
b.print_info();
}
}