Constructor Flashcards
are a special kind of method.
Constructors
What are the three peculiarities of Constructors?
- A constructor must have the same name as the class itself.
- Constructors do not have a return type—not even void.
- Constructors are invoked using the new operator when an object is created.
What role do Constructors play?
Initializing objects?
TRUE OR FALSE:
“A class normally provides a constructor without arguments.”
True
What are constructors with no arguments (ex. Circle()) referred to?
No-arg or no-argument constructor
TRUE OR FALSE
“A class may be defined without constructors. In this case, a no-arg constructor with an empty body is implicitly defined in the class.”
TRUE
When are default constructors provided automatically?
Default constructors are only provided automatically if no constructors are explicitly defined in the class.
How do you specify that you are referring to the field in “this” object and not the local parameter?
By using the “this” keyword.