0% found this document useful (0 votes)
1 views

Constructors

A constructor is a special method in a class with the same name as the class, lacking a return type. It is responsible for object creation, memory allocation, and initializing data members, and can be of four types: default, non-parameterized, parameterized, and copy. Constructors can be overloaded, and the 'this' keyword is used to refer to the current object, while the copy constructor is now deprecated in favor of using the assignment operator.

Uploaded by

amazinganish11
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Constructors

A constructor is a special method in a class with the same name as the class, lacking a return type. It is responsible for object creation, memory allocation, and initializing data members, and can be of four types: default, non-parameterized, parameterized, and copy. Constructors can be overloaded, and the 'this' keyword is used to refer to the current object, while the copy constructor is now deprecated in favor of using the assignment operator.

Uploaded by

amazinganish11
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Constructors

1. Constructor is a special method of a class.


2. It has same name as that of a class.
3. It does not have return type, not even void.
4. If programmer does not create the constructor, Java provides one
which is known as Default constructor.
5. If programmer defines the constructor then default constructor
provided by Java gets withdrawn.
6. Constructor gets executed only once in a lifetime of an object.
7. Its jobs are object creation, memory allocation and initializing the data
members.
8. Constructors are of 4 types that are, default, non-parameterized,
parameterized and copy.
9. Parameterized constructors accept the parameters.
10.Copy constructor is deprecated. Now the objects can be created
directly with the help of assignment operator. Copy constructor is not
needed for that. For Example:
Student S1, S2;
S1=new Student ( );
S2=S1;
11.Constructors can be overloaded.
12. ‘this’ keyword is commonly used in constructors which indicates the
current object.
13. Array of objects can be created using parameterized constructor in a
for loop.

You might also like