GoConqr hat ein neues Design! Sag uns, wie es dir gefällt.

Mindmap

public class Car(): (Blueprint/Template)

Edward Bill Englisch

Inhalt der Mindmap

public class Car(): (Blueprint/Template)

  1. Fields (Attributes): color, name, number of tires

    • Fields can be public or private
  2. Methods (Actions): Methods can be private, protected, or public. ReturnType (void, primitive type, or object)

    • Getters: getColor, getName, getNumberOfTires
      • This method returns a primitive or an object. Also, it does not accept any argument(s)
    • Setters: setName, setColor, setNumberOfTires
      • This method helps to set method arguments to the class fields using the "this" keyword e.g color = this.color.
    • Other methods: run(), brake()
  3. Constructor (Most important): Used to construct the class object in the driver program. Must be at least one.

    • No-arg constructor (Initialization constructor): does not accept any arguments and initializes the fields in the class
    • Constructor with arguments: Accepts arguments and is used to initialize the class fields
  4. Driver program: In the main program, to use the class, Car, as an object, we create an instance of that class (define it) e.g private Car car (we do this outside and above the main). Since the variable, car, is null we need to use the "new" keyword to construct the object. E,g in main, we do=> car = new Car("blue", Benz, 4). To use the method created in the class, Car, we do this=> car.setName("V7"). This will change the name of the car which was instantiated as "Benz". Thus, if we print car.getName(), we get V7 in the console

Informationen

Beschreibung
Mindmap am public class Car(): (Blueprint/Template), erstellt von Edward Bill am 12/09/2020.
Erstellt von
Edward Bill
Aufrufe
0
Bewertung

Feedback

Worum geht es?

Wie gefällt dir das neue Design?

Dein Eindruck