¡GoConqr estrena diseño! Cuéntanos qué te parece.

Mapa mental

public class Car(): (Blueprint/Template)

Edward Bill Inglés

Contenido del mapa

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

Información

Descripción
Mapa Mental sobre public class Car(): (Blueprint/Template), creado por Edward Bill el 12/09/2020.
Creado por
Edward Bill
Visitas
0
Valoración

Escríbenos

¿Sobre qué es tu mensaje?

¿Qué te parece el nuevo diseño?

¿Te gusta?