Constructors Flashcards

1
Q

How many arguments does the default constructor take?

A

None.

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

What is the access type of a default constructor?

A

It is the same as the access type of the class.

I.e., if the class is public, so is the default constructor.

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

T/F: A constructor is non-static

A

True.

It can access both static and non-static members of the class.

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

Does a constructor need to initialize all member variables of a class?

A

No.

Non-final members will be assigned a default value.

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

Can a constructor declare a return value?

A

No.

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

Can a constructor be declared private?

A

Yes.

This is used for implementing singleton classes.

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

Do all Java classes get a default constructor?

A

No.

If a class explicitly defines a constructor it will not get the default constructor.

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

What does the default constructor call?

A

The no-args constructor of the super class.

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

What must an abstract class declaration have to be valid?

A

It must have the abstract keyword and may not have a method body.

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

What does the final keyword mean when applied to a class? a method? a variable?

A

Applied to a class, it means no further sub-classing.

To a method it means no method overridding.

To a variable it makes it a constant.

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