TODAY JAVA SCHOOL

In java school, programming, design, computer general knowledge, web application, software, web services, social media, digital marketing, oops, concept of programming language, oops feature, console media, graphics medium, first programming, c, c ++ , Java, PHP, SQL, MySQL, HTML, HTML_5, J_query, JavaScript, Bootstrap, Framework, images with logos, examples, shared and explained.

https://www.amazon.in/b?node=26373545031&linkCode=ll2&tag=1234567801cdb-21&linkId=3b9882431b00409b44141e0344b35a15&language=en_IN&ref_=as_li_ss_tl

Breaking

Monday 22 June 2020

Multiple Constructor In C++ | Multiple Constructor In C++ Example| Multiple Constructor In C++ Program | Multiple Constructor In C++ Syntax | Multiple Constructor In C++ In Hindi

Multiple Constructor In C++

When we create different-different type of class inside  in a constructor to declare  so that method is known as multiple constructor in a class.

image of Multiple Constructor In C++

Fig:Multiple Constructor In C++ 

Syntax:

class classname

{

public:

class name()

{

 

}

classname(argument)

{

}

classname(classname &objectname)

{

}

};


Program:

#include<iostream.h>

#include<conio.h>

class BCA

{

private:

int a,b,c;

public:

BCA()

{

cout<<”multiple constructor”;

a=12;

b=23;

c=a+b;

}

BCA(int x,int y,int z)

{

 a=x;

b=y;

c=z;

}

BCA(BCA &p)

{

a=p.a;

b=p.b;

c=a*b;

}

void display()

{

cout<<a;

cout<<b;

cout<<c;

}

};

void main()

{

BCA a1;

BCA a2(10,20,30);

BCA a3(a2);

a1.display();

a2.display();

a3.display();

getch();

}

 

Output:

Multiple constructor

12 23 35

10 20 30

10 20 200

 



No comments:

Post a Comment