Constructors

This Cabbie class contains two constructors. We know they are constructors because they have the same name as the class: Cabbie. The first constructor is the default constructor:

public Cabbie() {

      name = null;
      myCab = null;

   }

Technically, this is not a default constructor. The compiler will provide a default constructor if you do not specify a constructor for this class. By definition, the reason it is called a default constructor here is because it is a constructor with no arguments. If you provide a constructor with arguments, the system will not provide a default constructor. The rule is that the default constructor is only provided if you provide no constructors.

In this constructor, the attributes Name and myCab are set to ...

Get Object-Oriented Thought Process, The, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.