Constructors Flashcards

1
Q

Constructor Definition

A

A constructor is a member method having the same name as
that of the class and is used to initialize the instance
variables of the Objects.

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

Return type of constructor

A

No return type; not even void

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

Use of constructor

A

To initialize data members / instance variables
Eg: class sum
{
int a, b;
sum() → constructor
{ 0=0,6=0;
}

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

How can constructor be invoked?

A

At the time of creating an object of a class

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

Constructor is automatically/manually called

A

Automatically

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

Features of constructor

A

same name as class name
No return type; not even void
called automatically when object is created
Used to initialize data members
constructor is ALWAYS public

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

Two types of constructors

A

Parameterized
Non-parameterized

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

Non parameterized constructor?

A

A constructor which Initialized the instance variables of an object with definite values readily available within it.

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

Parameterized constructor?

A

Initializes instance variables with the help of parameters passed in it at the time of creating an object

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

Default constructor

A

Non_parameterized constructor which is used to initialize instance variables with default values of datatype
! No syntax for constructor is written!

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

Constructor overloading?

A

Using a number of constructors with the same name but different types of parameters.

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