GoConqr has a new look! Let us know what you think.

Mind map

public class Car(): (Blueprint/Template)

Edward Bill English

Map content

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

Information

Description
Mind Map on public class Car(): (Blueprint/Template), created by Edward Bill on 12/09/2020.
Created by
Edward Bill
Views
0
Rating

Feedback

What is it about?

What do you think of the new look?

How do you like it?