Constructor Flashcards

1
Q

are a special kind of method.

A

Constructors

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the three peculiarities of Constructors?

A
  • 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What role do Constructors play?

A

Initializing objects?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

TRUE OR FALSE:
“A class normally provides a constructor without arguments.”

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are constructors with no arguments (ex. Circle()) referred to?

A

No-arg or no-argument constructor

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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.”

A

TRUE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

When are default constructors provided automatically?

A

Default constructors are only provided automatically if no constructors are explicitly defined in the class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you specify that you are referring to the field in “this” object and not the local parameter?

A

By using the “this” keyword.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly