Chapter 6 Flashcards
True or False, Constructors create and initialize new objects?
True
True or False, A constructor is a special method that is called when you use the new operator to create a new object
True
Using __ calls a constructor
new
What part is earthSpecies and what part is Species in Species earthSpecies = new Species();
- earthSpecies to be a name for an object
- in class Species.
- The second part, newSpecies(), creates and initializes a new object, whose address is then assigned to earthSpecies.
- Species() is a call to the constructor that Java provided for the class. The parentheses are empty because this particular constructor takes no arguments.
True/False .A constructor supplied by Java uses default initial values
True
True or False, the constructors create objects and give their instance variables default initial values. These values might not be what you want, however. Instead, you may wish to have some or all instance variables initialized to your specifications at the time an object is created. You can do this by writing your own constructors.
True
Constructors serve essentially the same purpose as ___
setters or set methods
True or False, A constructor can perform any action you write into its definition, but a constructor is meant to perform initializing actions, such as initializing the values of instance variables.
True
True or False, When you define a constructor, you do not specify any return type, not even void. These constructors look very much like our set methods, which are void methods.
True
Instance variables that you do not initialize are given ___ initial values by Java
default
True or False, A default constructor has no parameters
True
When you create a new object by using the operator new, you must always include a __ to a constructor.
call
Pet fish = new Pet(“Wanda”, 2, 0.25); , describe this line of code
The part Pet(“Wanda”, 2, 0.25) is a call to the constructor in Pet that takes three arguments:
This statement creates a new object to represent a pet named Wanda who is 2 years old and weighs 0.25 pound.
True of False, You cannot use an existing object to call a constructor
True
True of False, A constructor that calls a public method can cause a problem
True