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

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

Constructor Overloading In C++

In C++, We can have more than one constructor in a class with same name, as long as each has a different list of arguments.This concept is known as Constructor Overloading.

image of constructor overloading in c++

Fig: Constructor Overloading In C++ 

Syntax:

Class classname

{

----

-----

}

Class classname(argument)

{

----

------

};


Program:

#include<iostream.h>

#include<conio.h>

class BCA

{

int a,b,c;

public:

BCA()

{

a=b=c=0;

}

BCA(int a)

{

this->a=this->b=this->c=a;

}

BCA(int a, int b)

{

this->a=a;

this->b=b;

this->c=a+b;

}

void display()

{

cout<<”a=”<<a;

cout<<”b=”<<b;

cout<<”c=”<<c;

}

};

void main()

{

BCA a1;

a1.display();

BCA a2(10);

a2.display();

BCA a3(20,30);

a3.display();

getch();

}


Output:

a=0 b=0 c=0 a=10 b=10 c=10 a=20 b=30 c=9915


No comments:

Post a Comment