Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Class notes 21CS101T (OODP)

Rating
-
Sold
-
Pages
2
Uploaded on
16-03-2023
Written in
2022/2023

Notes were published by professors in the university

Institution
Course

Content preview

OODP UNIT 02


1. CONSTRUCTOR & TYPES:

• A constructor is a special member function whose task is to initialize the objects of its class.
• It is special because its name is same as the class name.
• The constructor is invoked whenever an object of its associated class is created.
• It is called constructor because it constructs the values of data members of the class.
• The syntax generally is as given below :
<class name> { arguments} ;

CHARACTERISTICS OF CONSTRUCTORS:

• They should be declared in the public section.
• They are invoked automatically when the objects are created.
• They do not have return types, not even void and they cannot return values.
• They cannot be inherited, though a derived class can call the base class constructor.
• Like other C++ functions, Constructors can have default arguments.
• Constructors can not be virtual.
• We can not refer to their addresses.
• An object with a constructor (or destructor) can not be used as a member of a union.
• They make ‘implicit calls’ to the operators new and delete when memory allocation is required.

TYPES OF CONSTRUCTORS:

• There are several forms in which a constructor can take its shape namely:

 Default Constructor
 Parameterized Constructors
 Copy constructor

DEFAULT CONSTRUCTOR:

• A constructor that accepts no parameters is called the default constructor.
• The default constructor for class A is A : : A ( )
• When a constructor is declared for a class initialization of the class objects becomes mandatory.

Example:

class add
{
int m, n ;
public :
add (void) ;
//code
};
add :: add (void)
{
m = 0; n = 0;
}

Written for

Institution
Course

Document information

Uploaded on
March 16, 2023
Number of pages
2
Written in
2022/2023
Type
Class notes
Professor(s)
Dr.m.subramaniam
Contains
All classes

Subjects

$8.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
parthiburk

Also available in package deal

Get to know the seller

Seller avatar
parthiburk SRM UNIVERSITY
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
3 year
Number of followers
0
Documents
7
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions